diff --git a/docs/sophia_stdlib.md b/docs/sophia_stdlib.md index ab31beb..6554810 100644 --- a/docs/sophia_stdlib.md +++ b/docs/sophia_stdlib.md @@ -700,6 +700,13 @@ List.last(l : list('a)) : option('a) Returns `Some` of the last element of a list or `None` if the list is empty. +### contains +``` +List.contains(e : 'a, l : list('a)) : bool +``` +Checks if list `l` contains element `e`. Equivalent to `List.find(x => x == e, l) != None`. + + ### find ``` List.find(p : 'a => bool, l : list('a)) : option('a) @@ -1040,6 +1047,13 @@ Option.force(o : option('a)) : 'a Forcefully escapes `option` wrapping assuming it is `Some`. Throws error on `None`. +### contains +``` +Option.contains(e : 'a, o : option('a)) : bool +``` +Returns `true` if and only if `o` contains element equal to `e`. Equivalent to `Option.match(false, x => x == e, o)`. + + ### on_elem ``` Option.on_elem(o : option('a), f : 'a => unit) : unit diff --git a/priv/stdlib/List.aes b/priv/stdlib/List.aes index 3405035..3a56856 100644 --- a/priv/stdlib/List.aes +++ b/priv/stdlib/List.aes @@ -15,10 +15,14 @@ namespace List = _::t => Some(t) function last(l : list('a)) : option('a) = switch(l) - [] => None - [x] => Some(x) + [] => None + [x] => Some(x) _::t => last(t) + function contains(e : 'a, l : list('a)) = switch(l) + [] => false + h::t => h == e || contains(e, t) + /** Finds first element of `l` fulfilling predicate `p` as `Some` or `None` * if no such element exists. */ diff --git a/priv/stdlib/Option.aes b/priv/stdlib/Option.aes index 4895e18..e364363 100644 --- a/priv/stdlib/Option.aes +++ b/priv/stdlib/Option.aes @@ -26,6 +26,8 @@ namespace Option = None => abort("Forced None value") Some(x) => x + function contains(e : 'a, o : option('a)) = o == Some(e) + function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o) function map(f : 'a => 'b, o : option('a)) : option('b) = switch(o) diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index e8f5931..208839d 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -39,7 +39,7 @@ simple_compile_test_() -> error(ErrBin) end end} || ContractName <- compilable_contracts(), Backend <- [aevm, fate], - not lists:member(ContractName, not_yet_compilable(Backend))] ++ + not lists:member(ContractName, not_compilable_on(Backend))] ++ [ {"Test file not found error", fun() -> {error, Errors} = aeso_compiler:file("does_not_exist.aes"), @@ -168,8 +168,11 @@ compilable_contracts() -> "lhs_matching" ]. -not_yet_compilable(fate) -> []; -not_yet_compilable(aevm) -> []. +not_compilable_on(fate) -> []; +not_compilable_on(aevm) -> + ["stdlib_include", + "manual_stdlib_include" + ]. %% Contracts that should produce type errors