Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include L end
val pp : 'a Base.pp -> unit Base.outfmt -> 'a list Base.pp
pp elt sep ppf l
prints the list l
on the formatter ppf
using sep
as separator, and elt
for printing the elements.
eq eq_elt l1 l2
tests the equality of l1
and l2
, comparing their elements with eq_elt
.
val find_map : ('a -> 'b option) -> 'a t -> 'b option
find_map f l
applies f
to the elements of l
in order, and returns the first result of the form Some v
, or None
if none exist.
filter_map f l
applies f
to every element of l
, filters out the None
elements and returns the list of the arguments of the Some
elements.
val concat_map : ('a -> 'b list) -> 'a t -> 'b list
filter_rev_map f l
is equivalent to filter_map f (List.rev l)
, but it only traverses the list once and is tail-recursive.
filteri_map f l
applies f
element wise on l
and keeps x
such that for e
in l
, f e = Some(x)
.
cut l k
returns a pair of lists (l1, l2)
such that l1
has length min (List.length l) k
and l1 @ l2
is equal to l
.
add_array a1 a2 l
returns a list containing the elements of l
, and the (corresponding) elements of a1
and a2
. Note that a1
and a2
should have the same lenght otherwise Invalid_argument
is raised.
same_length l1 l2
returns true
whenever l1
and l2
are lists of the same length. The function stops as soon as possible.
max ?cmp l
finds the max of list l
with compare function ?cmp
defaulting to Stdlib.compare
.
val assoc_eq : 'a Base.eq -> 'a -> ('a * 'b) list -> 'b
assoc_eq e k l
is List.assoc k l
with equality function e
.
val remove_phys_dups : 'a list -> 'a t
remove_phys_dups l
uniqify list l
keeping only the last element, using physical equality.
destruct l i
returns a triple (left_rev, e, right)
where e
is the i
-th element of l
, left_rev
is the reversed prefix of l
up to its i
-th element (excluded), and right
is the remaining suffix of l
(starting at its i+1
-th element).
reconstruct left_rev l right
concatenates (reversed) left_rev
, l
and right
. This function will typically be used in combination with destruct
to insert a sublist l
in the place of the element at the specified position in the specified list.
init n f
creates a list with f 0
up to f n
as its elements. Note that Invalid_argument
is raised if n
is negative.
val mem_sorted : 'a Base.cmp -> 'a -> 'a list -> bool
mem_sorted cmp x l
tells whether x
is in l
assuming that l
is sorted wrt cmp
.
val insert : 'a Base.cmp -> 'a -> 'a list -> 'a list
insert cmp x l
inserts x
in the list l
assuming that l
is sorted in increasing order wrt cmp
.
val insert_uniq : 'a Base.cmp -> 'a -> 'a list -> 'a list
insert_uniq cmp x l
inserts x
in the list l
assuming that l
is sorted in increasing order wrt cmp
, but only if x
does not occur in l
.
rev_mapi f [x1;..;xn]
returns f (n-1) xn; ..; f 0 x1
.
swap i xs
put the i-th element (counted from 0) of xs
at the head.
val fold_left_while : ('a -> 'b -> 'a) -> ('b -> bool) -> 'a -> 'b t -> 'a
fold_left_while f cond a [b1 b2 ..]
computes (f..(f (f a b1) b2)..bm) where cond
is true for b1..bm and false for b_m+1 or bm is last element
remove_first f l
removes from l
the first element satisfying f
.
split f l
returns the tuple (l1,x,l2)
such that x
is the first element of l
satisying f
, l1
is the sub-list of l
preceding x
, and l2
is the sub-list of l
following x
: l = l1 :: x :: l2
.
iter_head_tail f l
iterates f
on all pairs (head, tail) of l
.
sequence_opt l
is Some [x1; x2; ...]
if all elements of l
are of the form Some xi
, and None
if there is a None
in l
.