Module MzList

module MzList: sig .. end
A bunch of useful functions for lists.

val map2i : (int -> 'a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
Same as map2 but pass an extra parameter that represents the index
val fold_righti : (int -> 'elt -> 'acc -> 'acc) -> 'elt list -> 'acc -> 'acc
Same as fold_right except that the function takes the current index in the list. The index starts counting from the right of the list, so the first call will pass 0 for i.
val fold_lefti : (int -> 'acc -> 'elt -> 'acc) -> 'acc -> 'elt list -> 'acc
Same as fold_left except that the function takes the current index in the list
val fold_left2i : (int -> 'acc -> 'b -> 'c -> 'acc) -> 'acc -> 'b list -> 'c list -> 'acc
Same as fold_left2 except that the function takes the current index in the list
val fold_left3 : ('acc -> 't1 -> 't2 -> 't3 -> 'acc) ->
'acc -> 't1 list -> 't2 list -> 't3 list -> 'acc
Same as fold_left2 but with three lists.
val reduce : ('a -> 'a -> 'a) -> 'a list -> 'a
Same as fold_left, but start folding on the head of the list instead of giving an initial element.
val iter2i : (int -> 'a -> 'b -> unit) -> 'a list -> 'b list -> unit
Same as List.iteri but with two lists.
val iter3 : ('a -> 'b -> 'c -> unit) -> 'a list -> 'b list -> 'c list -> unit
Same as List.iter but with three lists.
val combine3 : 'a list -> 'b list -> 'c list -> ('a * 'b * 'c) list
Same as List.combine but for triples instead of pairs.
val split3 : ('a * 'b * 'c) list -> 'a list * 'b list * 'c list
Same as List.split but for triples instead of pairs.
val make : int -> (int -> 'a) -> 'a list
make n f creates [f 1; ...; f n].
val last : 'a list -> 'a
Get the last element of a list.
val ignore_map : ('a -> 'b) -> 'a list -> unit
Map a function and then discard the result.
val check_for_duplicates : ('a -> 'a -> int) -> 'a list -> ('a * 'a) option
Checking for duplicates in a list. check_for_duplicates compare xs returns either Some (x1, x2) where x1 and x2 are distinct elements of the list xs such that compare x1 x2 is zero, or None, if no such two elements exist.
val exit_if_duplicates : ('b -> 'b -> int) -> ('a -> 'b) -> 'a list -> ('a -> 'a list) -> 'a list
Checking for duplicates in a list. The comparison function operates on values of type 'b, while the list elements have type 'a. A projection function maps 'a to 'b. If a duplicate element is found, the exit function is invoked.
val max : int list -> int
Find the biggest element in a list
val filter_some : 'a option list -> 'a list
Turns [Some a; None; ...] into [a; ...]
val map_some : ('a -> 'b option) -> 'a list -> 'b list
Composition of List.map and filter_some.
val nth_opt : 'a list -> int -> 'a option
Just like List.nth except it returns an Option type.
val index : ('a -> bool) -> 'a list -> int
Find the index of the first element in a list that satisfies a predicate.
val take : ('a -> 'b option) -> 'a list -> ('a list * ('a * 'b)) option
If f may convert an 'a into a 'b, then take f l returns the first convertible element in the list, along with the remaining elements in the list.
val take_bool : ('a -> bool) -> 'a list -> ('a list * 'a) option
val find_opt : ('a -> 'b option) -> 'a list -> 'b option
val find_opti : (int -> 'a -> 'b option) -> 'a list -> 'b option
val flatten_map : ('a -> 'b list) -> 'a list -> 'b list
val split_map : ('a -> 'b * 'c) -> 'a list -> 'b list * 'c list
split_map f xs is equivalent to List.split (List.map f xs).
val cut : int -> 'a list -> 'a list
val equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
Equality of lists, up to equality of elements.
val cps_map : ('a -> ('b -> 'c) -> 'c) -> 'a list -> ('b list -> 'c) -> 'c
A CPS version of List.map.
val map : ('a -> 'a) -> 'a list -> 'a list
A sharing-preserving version of List.map.