From 059059ac879423685e1aba6ad1e6ee487272bc49 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Thu, 2 Sep 2021 13:02:18 +0300 Subject: [PATCH] Update docs --- docs/sophia_features.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/sophia_features.md b/docs/sophia_features.md index 263eb12..48e6c8a 100644 --- a/docs/sophia_features.md +++ b/docs/sophia_features.md @@ -121,7 +121,7 @@ contract IntHolder = type state = int entrypoint init(x) = x entrypoint get() = state - + main contract IntHolderFactory = stateful entrypoint new(x : int) : IntHolder = let ih = Chain.create(x) : IntHolder @@ -482,6 +482,25 @@ function g(p : int * option(int)) : int = b ``` +Guards are boolean functions that can be used on patterns in both switch +statements and functions definitions: + +```sophia +function get_left_if_positive(x : one_or_both('a, 'b)) : option('a) = + switch(x) + Left(x) | x > 0 => Some(x) + Both(x, _) | x > 0 => Some(x) + _ => None +``` + +```sophia +function + get_left_if_positive : one_or_both('a, 'b) => option('a) + get_left(Left(x)) | x > 0 = Some(x) + get_left(Both(x, _)) | x > 0 = Some(x) + get_left(_) = None +``` + *NOTE: Data types cannot currently be recursive.* ## Lists @@ -851,4 +870,4 @@ Some chain operations (`Oracle.` and `AENS.`) have an optional delegation signature. This is typically used when a user/accounts would like to allow a contract to act on it's behalf. The exact data to be signed varies for the different operations, but in all cases you should prepend -the signature data with the `network_id` (`ae_mainnet` for the æternity mainnet, etc.). \ No newline at end of file +the signature data with the `network_id` (`ae_mainnet` for the æternity mainnet, etc.).