Module Stdlib.List
Extensions to the List module
is_empty l is true if and only if l has no elements. It is equivalent to compare_length_with l 0 = 0.
val compare :
('a -> 'a -> int) ->
'a Misc.Stdlib.List.t ->
'a Misc.Stdlib.List.t ->
intThe lexicographic order supported by the provided order. There is no constraint on the relative lengths of the lists.
val equal :
('a -> 'b -> bool) ->
'a Misc.Stdlib.List.t ->
'b Misc.Stdlib.List.t ->
boolReturns true if and only if the given lists have the same length and content with respect to the given equality function.
val some_if_all_elements_are_some :
'a option Misc.Stdlib.List.t ->
'a Misc.Stdlib.List.t optionIf all elements of the given list are Some _ then Some xs is returned with the xs being the contents of those Somes, with order preserved. Otherwise return None.
val map_option :
('a -> 'b option) ->
'a Misc.Stdlib.List.t ->
'b Misc.Stdlib.List.t optionmap_option f l is some_if_all_elements_are_some (map f l), but with short circuiting.
val map2_option :
('a -> 'b -> 'c option) ->
'a Misc.Stdlib.List.t ->
'b Misc.Stdlib.List.t ->
'c Misc.Stdlib.List.t optionval map2_prefix :
('a -> 'b -> 'c) ->
'a Misc.Stdlib.List.t ->
'b Misc.Stdlib.List.t ->
'c Misc.Stdlib.List.t * 'b Misc.Stdlib.List.tlet r1, r2 = map2_prefix f l1 l2 If l1 is of length n and l2 = h2 @ t2 with h2 of length n, r1 is List.map2 f l1 h1 and r2 is t2.
concat_map2 f l1 l2 gives the same result as concat (map2 f l1 l2). Tail-recursive.
Same as List.iter2, but the function is applied to the index of the element as first argument (counting from 0)
val split_at :
int ->
'a Misc.Stdlib.List.t ->
'a Misc.Stdlib.List.t * 'a Misc.Stdlib.List.tsplit_at n l returns the pair before, after where before is the n first elements of l and after the remaining ones. If l has less than n elements, raises Invalid_argument.
val map_sharing : ('a -> 'a) -> 'a Misc.Stdlib.List.t -> 'a Misc.Stdlib.List.tmap_sharing f l is map f l. If for all elements of the list f e == e then map_sharing f l == l
fold_lefti f init l is like fold_left but also takes as parameter the zero-based index of the element
val fold_left_map2 :
('acc -> 'a -> 'b -> 'acc * 'r) ->
'acc ->
'a list ->
'b list ->
'acc * 'r listfold_left_map2 is a combination of fold_left2 and map2 that threads an accumulator through calls to f.
val chunks_of :
int ->
'a Misc.Stdlib.List.t ->
'a Misc.Stdlib.List.t Misc.Stdlib.List.tchunks_of n t returns a list of nonempty lists whose concatenation is equal to the original list. Every list has n elements, except for possibly the last list, which may have fewer. chunks_of raises if n <= 0.
Returns true if and only if the given list, with respect to the given equality function on list members, is a prefix of the list of_.
val find_and_chop_longest_common_prefix :
equal:('a -> 'a -> bool) ->
first:'a list ->
second:'a list ->
'a Misc.Stdlib.List.longest_common_prefix_resultReturns the longest list that, with respect to the provided equality function, is a prefix of both of the given lists. The input lists, each with such longest common prefix removed, are also returned.
val iter_until_error :
f:('a -> (unit, 'b) Stdlib.Result.t) ->
'a list ->
(unit, 'b) Stdlib.Result.titer_until_error f l applies f to each element of l, in order, short-circuiting in the case f returns Error on any element.
val merge_iter :
cmp:('a -> 'b -> int) ->
left_only:('a -> unit) ->
right_only:('b -> unit) ->
both:('a -> 'b -> unit) ->
'a Misc.Stdlib.List.t ->
'b Misc.Stdlib.List.t ->
unitIterates over two sorted lists, calling left_only on those elements that appear only in the left list, right_only on those elements that appear only in the right list, and both on those elements that appear in both.
val merge_fold :
cmp:('a -> 'b -> int) ->
left_only:('acc -> 'a -> 'acc) ->
right_only:('acc -> 'b -> 'acc) ->
both:('acc -> 'a -> 'b -> 'acc) ->
init:'acc ->
'a Misc.Stdlib.List.t ->
'b Misc.Stdlib.List.t ->
'accFolds over two sorted lists, calling left_only on those elements that appear only in the left list, right_only on those elements that appear only in the right list, and both on those elements that appear in both.