Added contains functions in List and Option. Fixed one type error catch
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user