list
Lists
type t<elt> = list<elt>
The type `t` is an alias for the predefined type `list`.let 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>)
.
let length: <elt>(_: 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
.
let size: <elt>(_: t<elt>) => nat
The call List.size(l)
is the number of elements in the list l
.
let head: <elt>(_: t<elt>) => option<elt>
The call List.head(l)
, where l
is a list, is None()
if l
is
empty; otherwise, Some(hd)
, where hd
is the head of the list.
let head_opt: <elt>(_: t<elt>) => option<elt>
**Deprecated:** Use `List.head` instead.The call List.head_opt(l)
, where l
is a list, is None()
if l
is
empty; otherwise, Some(hd)
, where hd
is the head of the list.
let tail: <elt>(_: t<elt>) => option<t<elt>>
The call List.tail(l)
, where l
is a list, is None()
if l
is
empty; otherwise, Some(tl)
, where tl
is the tail of the list.
let tail_opt: <elt>(_: t<elt>) => option<t<elt>>
**Deprecated:** Use `List.tail` instead.The call List.tail_opt(l)
, where l
is a list, is None()
if l
is
empty; otherwise, Some(tl)
, where tl
is the tail of the list.
let map: <src, dst>(_: (_: src) => dst) => (_: list<src>) => list<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
.
let iter: <elt>(_: (_: elt) => unit) => (_: 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)}
.
let fold_left: <elt, acc>(_: (_: [acc, elt]) => acc) => (_: acc) => (_: t<elt>) => acc
The call List.fold_left(f, init, list([a1; ...; an]))
is
f (... (f (f(init, a1)), a2), ...), an)
.
let fold_right: <elt, acc>(_: (_: [elt, acc]) => acc) => (_: t<elt>) => (_: acc) => acc
The call List.fold_right(f, list([a1; ...; an]), init)
is
f (a1, f (a2, (..., f (an, init))...))
.
let fold: <elt, acc>(_: (_: [acc, elt]) => acc) => (_: t<elt>) => (_: 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)
.
let cons: <elt>(_: elt) => (_: t<elt>) => t<elt>
The call List.cons(e, l)
is list([e, ...l])
.
let find_opt: <elt>(_: (_: elt) => bool) => (_: t<elt>) => option<elt>
The call List.find_opt(pred, list)
is None()
if no element of the
list list
satisfies the predicate pred
; otherwise, it is
Some(e)
, where e
is the leftmost element in list
that satisfies
pred
. The order of the calls of pred
is not specified.
let filter_map: <src, dst>(_: (_: src) => option<dst>) => (_: 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()
. Note:
f
is called on all elements of l
. The order of the calls of
f
is not specified.
let update: <elt>(_: (_: elt) => option<elt>) => (_: t<elt>) => t<elt>
The call List.update(f, l)
is the list l
where the elements e
such that f(e)
is Some(v)
have been replaced by v
.
let update_with: <elt>(_: (_: elt) => bool) => (_: elt) => (_: 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
.