Added contains
functions in List and Option. Fixed one type error catch
This commit is contained in:
parent
ed5447e430
commit
7e32ef57c2
@ -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,10 @@ namespace Option =
|
||||
None => abort("Forced None value")
|
||||
Some(x) => x
|
||||
|
||||
function contains(e : 'a, o : option('a)) = switch(o)
|
||||
None => false
|
||||
Some(x) => x == 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
|
||||
|
||||
@ -316,8 +319,8 @@ failing_contracts() ->
|
||||
" x : int\n"
|
||||
"against the expected type\n"
|
||||
" string">>,
|
||||
<<?Pos(14, 24)
|
||||
"No record type with fields y, z (at line 14, column 24)">>,
|
||||
<<?Pos(14, 35)
|
||||
"No record type with fields z, y (at line 14, column 35)">>,
|
||||
<<?Pos(15, 26)
|
||||
"The field z is missing when constructing an element of type r2 (at line 15, column 26)">>,
|
||||
<<?Pos(15, 24)
|
||||
|
Loading…
x
Reference in New Issue
Block a user