module List: Extlib.ExtList.ListList operations.type'at ='a list
include List.Enumerable
include List.Mappable
val length : 'a list -> intval hd : 'a list -> 'aEmpty_list if the
list is empty.val tl : 'a list -> 'a listEmpty_list if
the list is empty.val is_empty : 'a list -> boolis_empty e returns true if e does not contains any element.val cons : 'a -> 'a list -> 'a listcons h t returns the list starting with h and continuing as tval first : 'a list -> 'aEmpty_list if
the list is empty (similar to hd).val last : 'a list -> 'aEmpty_list if
the list is empty. This function takes linear time.val at : 'a list -> int -> 'aat l n returns the n-th element of the list l or raise
Invalid_index is the index is outside of l bounds.val rev : 'a list -> 'a listval append : 'a list -> 'a list -> 'a list@.
Tail-recursive (length of the first argument).val rev_append : 'a list -> 'a list -> 'a listList.rev_append l1 l2 reverses l1 and concatenates it to l2.
This is equivalent to List.rev l1 @ l2, but rev_append is
more efficient.val concat : 'a list list -> 'a listval flatten : 'a list list -> 'a listconcat.val make : int -> 'a -> 'a listString.make, make n x returns a
list containing n elements x.val init : int -> (int -> 'a) -> 'a listArray.init, init n f returns the list containing
the results of (f 0),(f 1).... (f (n-1)).
Raise Invalid_arg "ExtList.init" if n < 0.val iter : ('a -> unit) -> 'a list -> unitList.iter f [a1; ...; an] applies function f in turn to
a1; ...; an. It is equivalent to
begin f a1; f a2; ...; f an; () end.val iteri : (int -> 'a -> 'b) -> 'a list -> unititeri f l will call (f 0 a0);(f 1 a1) ... (f n an) where
a0..an are the elements of the list l.val map : ('a -> 'b) -> 'a list -> 'b listmap f [a1; ...; an] applies function f to a1, ..., an,
and builds the list [f a1; ...; f an]
with the results returned by f. Tail-recursive.val mapi : (int -> 'a -> 'b) -> 'a list -> 'b listmapi f l will build the list containing
(f 0 a0);(f 1 a1) ... (f n an) where a0..an are the elements of
the list l.val rev_map : ('a -> 'b) -> 'a list -> 'b list
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'aList.fold_left f a [b1; ...; bn] is
f (... (f (f a b1) b2) ...) bn. Tail-recursive.val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'bList.fold_right f [a1; ...; an] b is
f a1 (f a2 (... (f an b) ...)). Tail-recursive.val reduce : ('a -> 'a -> 'a) -> 'a list -> 'aList.reduce f h::t is fold_left f h t.Invalid_argument on empty lists.val max : 'a list -> 'amax l returns the largest value in l as judged by
Pervasives.compareval min : 'a list -> 'amin l returns the smallest value in l as judged by
Pervasives.compareval iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unitList.iter2 f [a1; ...; an] [b1; ...; bn] calls in turn
f a1 b1; ...; f an bn.Different_list_size if the two lists have
different lengths.val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c listList.map2 f [a1; ...; an] [b1; ...; bn] is
[f a1 b1; ...; f an bn].Different_list_size if the two lists have
different lengths. Tail-recursive.val rev_map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c listList.rev_map2 f l1 l2 gives the same result as
List.rev (List.map2 f l1 l2), but is tail-recursive and
more efficient.val fold_left2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'aList.fold_left2 f a [b1; ...; bn] [c1; ...; cn] is
f (... (f (f a b1 c1) b2 c2) ...) bn cn.Different_list_size if the two lists have
different lengths.val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'cList.fold_right2 f [a1; ...; an] [b1; ...; bn] c is
f a1 b1 (f a2 b2 (... (f an bn c) ...)).Different_list_size if the two lists have
different lengths. Tail-recursive.val for_all : ('a -> bool) -> 'a list -> boolfor_all p [a1; ...; an] checks if all elements of the list
satisfy the predicate p. That is, it returns
(p a1) && (p a2) && ... && (p an).val exists : ('a -> bool) -> 'a list -> boolexists p [a1; ...; an] checks if at least one element of
the list satisfies the predicate p. That is, it returns
(p a1) || (p a2) || ... || (p an).val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> boolList.for_all, but for a two-argument predicate.Invalid_argument if the two lists have
different lengths.val exists2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> boolList.exists, but for a two-argument predicate.Invalid_argument if the two lists have
different lengths.val mem : 'a -> 'a list -> boolmem a l is true if and only if a is equal
to an element of l.val memq : 'a -> 'a list -> boolList.mem, but uses physical equality instead of structural
equality to compare list elements.val find : ('a -> bool) -> 'a list -> 'afind p l returns the first element of l such as p x
returns true or raises Not_found if such an element
has not been found.val find_exn : ('a -> bool) -> exn -> 'a list -> 'afind_exn p e l returns the first element of l such as p x
returns true or raises e if such an element has not been found.val findi : (int -> 'a -> bool) -> 'a list -> int * 'afindi p e l returns the first element ai of l along with its
index i such that p i ai is true, or raises Not_found if no
such element has been found.val find_map : ('a -> 'b option) -> 'a list -> 'bfind_map pred list finds the first element of list for which
pred element returns Some r. It returns r immediately
once found or raises Not_found if no element matches the
predicate. See also List.filter_map.val rfind : ('a -> bool) -> 'a list -> 'arfind p l returns the last element x of l such as p x returns
true or raises Not_found if such element as not been found.val filter : ('a -> bool) -> 'a list -> 'a listfilter p l returns all the elements of the list l
that satisfy the predicate p. The order of the elements
in the input list is preserved.val filter_map : ('a -> 'b option) -> 'a list -> 'b listfilter_map f l calls (f a0) (f a1).... (f an) where a0..an are
the elements of l. It returns the list of elements bi such as
f ai = Some bi (when f returns None, the corresponding element of
l is discarded).val find_all : ('a -> bool) -> 'a list -> 'a list
val partition : ('a -> bool) -> 'a list -> 'a list * 'a listpartition p l returns a pair of lists (l1, l2), where
l1 is the list of all the elements of l that
satisfy the predicate p, and l2 is the list of all the
elements of l that do not satisfy p.
The order of the elements in the input list is preserved.val index_of : 'a -> 'a list -> int optionindex_of e l returns the index of the first occurrence of e
in l, or None if there is no occurrence of e in lval index_ofq : 'a -> 'a list -> int optionindex_ofq e l behaves as index_of e l except it uses
physical equalityval rindex_of : 'a -> 'a list -> int optionrindex_of e l returns the index of the last occurrence of e
in l, or None if there is no occurrence of e in lval rindex_ofq : 'a -> 'a list -> int optionrindex_ofq e l behaves as rindex_of e l except it uses
physical equalityval unique : ?cmp:('a -> 'a -> bool) -> 'a list -> 'a listunique cmp l returns the list l without any duplicate element.
Default comparator ( = ) is used if no comparison function specified.
This function takes O(n²) time.
See also sort_unique to save time in cases when reordering the list is acceptable
val assoc : 'a -> ('a * 'b) list -> 'bassoc a l returns the value associated with key a in the list of
pairs l. That is,
assoc a [ ...; (a,b); ...] = b
if (a,b) is the leftmost binding of a in list l.
Raise Not_found if there is no value associated with a in the
list l.val assoc_inv : 'a -> ('b * 'a) list -> 'bassoc_inv b l returns the key associated with value b in the list of
pairs l. That is,
assoc b [ ...; (a,b); ...] = a
if (a,b) is the leftmost binding of a in list l.
Raise Not_found if there is no key associated with b in the
list l.val assq : 'a -> ('a * 'b) list -> 'bList.assoc but with physical equalityval mem_assoc : 'a -> ('a * 'b) list -> bool
val mem_assq : 'a -> ('a * 'b) list -> boolList.mem_assoc but with physical equality.val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) listremove_assoc a l returns the list of
pairs l without the first pair with key a, if any.
Tail-recursive.val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) listList.remove_assoc, but uses physical equality instead
of structural equality to compare keys. Tail-recursive.val split_at : int -> 'a list -> 'a list * 'a listsplit_at n l returns two lists l1 and l2, l1 containing the
first n elements of l and l2 the others. Raise Invalid_index if
n is outside of l size bounds.val split_nth : int -> 'a list -> 'a list * 'a listsplit_at.val remove : 'a list -> 'a -> 'a listremove l x returns the list l without the first element x found
or returns l if no element is equal to x. Elements are compared
using ( = ).val remove_if : ('a -> bool) -> 'a list -> 'a listremove_if cmp l is similar to remove, but with cmp used
instead of ( = ).val remove_all : 'a list -> 'a -> 'a listremove_all l x is similar to remove but removes all elements that
are equal to x and not only the first one.val take : int -> 'a list -> 'a listtake n l returns up to the n first elements from list l, if
available.val drop : int -> 'a list -> 'a listdrop n l returns l without the first n elements, or the empty
list if l have less than n elements.val take_while : ('a -> bool) -> 'a list -> 'a listtakewhile f xs returns the first elements of list xs
which satisfy the predicate f.val drop_while : ('a -> bool) -> 'a list -> 'a listdropwhile f xs returns the list xs with the first
elements satisfying the predicate f dropped.val interleave : ?first:'a -> ?last:'a -> 'a -> 'a list -> 'a listinterleave ~first ~last sep [a1;a2;a3;...;an] returns
first; a1; sep; a2; sep; a3; sep; ...; sep; an
Abstraction layer.
val enum : 'a list -> 'a Enum.tval of_enum : 'a Enum.t -> 'a listval backwards : 'a list -> 'a Enum.tval of_backwards : 'a Enum.t -> 'a listval split : ('a * 'b) list -> 'a list * 'b listsplit [(a1,b1); ...; (an,bn)] is ([a1; ...; an], [b1; ...; bn]).
Tail-recursive.val combine : 'a list -> 'b list -> ('a * 'b) listcombine [a1; ...; an] [b1; ...; bn] is
[(a1,b1); ...; (an,bn)].Different_list_size if the two lists
have different lengths. Tail-recursive.val make_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> intmake_compare c generates the lexicographical order on lists
induced by cval sort : ?cmp:('a -> 'a -> int) -> 'a list -> 'a listcompare).val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a listList.sort, but the sorting algorithm is guaranteed to
be stable (i.e. elements that compare equal are kept in their
original order) .
The current implementation uses Merge Sort. It runs in constant
heap space and logarithmic stack space.
val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a listl1 and l2 are sorted according to the
comparison function cmp, merge cmp l1 l2 will return a
sorted list containting all the elements of l1 and l2.
If several elements compare equal, the elements of l1 will be
before the elements of l2.
Not tail-recursive (sum of the lengths of the arguments).val sort_unique : ('a -> 'a -> int) -> 'a list -> 'a listsort_unique cmp l returns the list l sorted and without any duplicate element. cmp is a usual comparison function providing linear order.
This function takes O(n log n) time.
val group : ('a -> 'a -> int) -> 'a list -> 'a list listgroup cmp l returns list of groups and each group consists of elements judged equal by comparison function cmp. Groups in the resulting list appear in order given by cmp. All groups are always nonempty. group returns [] only if l is empty.
For example group cmp [f;c;b;e;d;a] can give [[a;b];[c];[d;e;f]] if following conditions are met:
cmp a b = 0, cmp b c = -1, cmp c d = -1, cmp d e = 0,...
exception Empty_list
Empty_list is raised when an operation applied on an empty list
is invalid : hd for example.exception Invalid_index of int
Invalid_index is raised when an indexed access on a list is
out of list bounds.exception Different_list_size of string
Different_list_size is raised when applying functions such as
iter2 on two lists having different size.val t_of_sexp : (Sexplib.Sexp.t -> 'a) -> Sexplib.Sexp.t -> 'a tval sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.tval print : ?first:string ->
?last:string ->
?sep:string ->
('a Extlib.InnerIO.output -> 'b -> unit) ->
'a Extlib.InnerIO.output -> 'b t -> unitval sprint : ?first:string ->
?last:string ->
?sep:string ->
('a Extlib.InnerIO.output -> 'b -> unit) ->
'b t -> stringval t_printer : 'a Value_printer.t -> 'a t Value_printer.tval nth : 'a list -> int -> 'aat.val takewhile : ('a -> bool) -> 'a list -> 'a listList.take_whileval dropwhile : ('a -> bool) -> 'a list -> 'a listList.drop_whileList with functions
behaving slightly differently but having the same name. This is by design:
the functions meant to override the corresponding functions of List.
To take advantage of these overrides, you probably want to
or . For instance, to open a version of List
with exceptionless error management, you may write
open List, Exceptionless. To locally replace module
List with a module of
the same name but with exceptionless error management, you may
write module List = List include Exceptionlessmodule List.Exceptionless:sig..end
module List.Labels:sig..end
List with labels.