Merge pull request #278 from aeternity/contains-fun
Added `contains` functions in List and Option. Fixed one type error
This commit is contained in:
commit
6c23fd0d41
@ -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
|
||||
|
@ -19,6 +19,10 @@ namespace List =
|
||||
[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.
|
||||
*/
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user