Stdlib320.List
nth l i
is the i
th element of l
if i >= 0
and i < length l
.
Raises an exception otherwise.
Same as the previous function, but is None
in the case of failure.
Combines a list of lists from left to right, e.g., concat [[1;2;3];[4;5;6];[7;8;9]] = [1;2;3;4;5;6;7;8;9]
Mapping function for lists. map f l
applies f
to every element of l
, e.g, map abs [-1;-2;-3] = [1;2;3]
.
Filtering function for lists. filter f l
is the element of l
(in order) which satisfy the predicate f
, e.g, filter ((<) 5) [3;4;5;6;7] = [6;7]
.
Left-associative folding function for lists. fold_left op init [x_1;x_2;...;x_n]
is equivalent to op (...(op (op init x_1) x_2)...) x_n
.
Right-associative folding function for lists. fold_right op [x_1;x_2;...;x_n]
is equivalent to op x_1 (op x_2 (...(op x_n base)...))
.
filter_map f l
is equivalent to the list filter Option.is_some (map f l)
but with the Some
constructors removed from each element.
concat_map f l
is equivalent to concat (map f l)
Membership predicate for lists. mem x l
is
true
if x
appears in l
false
otherwise.Finds based on a predicate. find f l
is the first appearance of an element of l
which satisfies f
.
Raises a Not_found
exception otherwise.
Same as the previous function, but is None
in the case of failure.
Take a prefix of a list. take i l
is the list containing the first min i (length l)
elements of l
, given i >= 0
.
Raises an Invalid_argument
exception otherwise.
drops the first min i (length l)
elements of l
and returns the remaining elements, given i >= 0
.
Raises an Invalid_argument
exception otherwise.
take_while f l
is the longest prefix of l
in which all elements satisfy the predicate f
.
drop_while f l
is equivalent to drop (length (take_while f l)) l
Generic sorting function for lists. sort f l
has the same elements as l
, but sorted according to the comparing function f
.
Membership function for association lists. assoc x l
is equivalent to
snd (find (fun (k, v) -> k = x))
Same as the previous function, but is None
in the case of failure.