list
Lists
type t<elt> = list<elt>
The type `t` is an alias for the predefined type `list`.empty: <elt>t<elt>
The value List.empty is the empty list. It is a synonym for
list([]). In some contexts, it is useful to annotate it with its
type, for example: (empty as list<int>).
length: <elt>(list: t<elt>) => nat
The call List.length(l) is the number of elements in the list
l. Note: List.length is another name for List.size.
size: <elt>(list: t<elt>) => nat
The call List.size(l) is the number of elements in the list l.
head: <elt>(list: t<elt>) => option<elt>
The call List.head(l), where l is a list, is ["None" as "None"]
if l is empty; otherwise, ["Some" as "Some", hd], where hd is
the head of the list.
tail: <elt>(list: t<elt>) => option<t<elt>>
The call List.tail(l), where l is a list, is ["None" as "None"]
if l is empty; otherwise, ["Some" as "Some", tl], where tl
is the tail of the list.
head_and_tail: <elt>(list: t<elt>) => option<elt,t< elt>>
The call List.head_and_tail(l), where l is a list, is
["None" as "None"] if l is empty; otherwise,
["Some" as "Some", [hd,tl]], where hd and tl are the head and
tail of the list, respectively.
map: <src, dst>(f: (_: src) => dst, list: t<src>) => t<dst>
The call List.map(f, list([a1; ...; an])) applies the function f to
a1, ..., an (from left to right), and builds the list
list([f(a1); ...; f(an)]) with the results returned by f.
iter: <elt>(f: (_: elt) => unit, list: t<elt>) => unit
The call List.iter(f, list([a1; ...; an])) applies the function f
in turn to list([a1; ...; an]). It is equivalent to {f(a1);
f(a2); ...; f(an)}.
fold_left: <elt, acc>(f: (_: [acc, elt]) => acc, init: acc, list: t<elt>) => acc
The call List.fold_left(f, init, list([a1; ...; an])) is
f (... (f (f(init, a1)), a2), ...), an).
fold_right: <elt, acc>(f: (_: [elt, acc]) => acc, list: t<elt>, init: acc) => acc
The call List.fold_right(f, list([a1; ...; an]), init) is
f (a1, f (a2, (..., f (an, init))...)).
fold: <elt, acc>(f: (_: [acc, elt]) => acc, list: t<elt>, init: acc) => acc
The call List.fold(f, list([a1; ...; an]), init) is
f (... (f (f (init, a1), a2) ...), an). Note:
List.fold_left(f, init, list) is the same as List.fold(f, list, init).
cons: <elt>(elt: elt, list: t<elt>) => t<elt>
The call List.cons(e, l) is list([e, ...l]).
find_opt: <elt>(f: (_: elt) => bool, list: t<elt>) => option<elt>
The call List.find_opt(pred, list) is ["None" as "None"] if no
element of the list list satisfies the predicate pred; otherwise,
it is ["Some" as "Some", e], where e is the leftmost element in
list that satisfies pred. The order of the calls of pred is not
specified.
filter_map: <src, dst>(filter: (_: src) => option<dst>, list: list<src>) => list<dst>
The call List.filter_map(f, l) is the maximal sub-list of l such
that the call of function f on its elements is not
["None" as "None"]. Note: f is called on all elements of l. The
order of the calls of f is not specified.
update: <elt>(filter: (_: elt) => option<elt>, list: t<elt>) => t<elt>
The call List.update(f, l) is the list l where the elements e
such that f(e) is ["Some" as "Some", v] have been replaced by v.
update_with: <elt>(pred: (_: elt) => bool, default: elt, list: t<elt>) => t<elt>
The call List.update_with(p,d,l) is the list l where the elements
e such that satisfy the predicate p are replaced by d.