CCListLabelsSourceFast internal iterator.
include module type of ListLabelsReturn the length (number of elements) of the given list.
Return the first element of the given list.
Return the given list without its first element.
Return the n-th element of the given list. The first element (head of the list) is at position 0.
List reversal.
rev_append l1 l2 reverses l1 and concatenates it with l2. This is equivalent to (rev l1) @ l2, but rev_append is tail-recursive and more efficient.
Concatenate a list of lists. The elements of the argument are all concatenated together (in the same order) to give the result. Not tail-recursive (length of the argument + length of the longest sub-list).
iter ~f [a1; ...; an] applies function f in turn to a1; ...; an. It is equivalent to begin f a1; f a2; ...; f an; () end.
fold_left_map is a combination of fold_left and map that threads an accumulator through calls to f.
fold_left ~f ~init [b1; ...; bn] is f (... (f (f init b1) b2) ...) bn.
iter2 ~f [a1; ...; an] [b1; ...; bn] calls in turn f a1 b1; ...; f an bn.
map2 ~f [a1; ...; an] [b1; ...; bn] is [f a1 b1; ...; f an bn].
fold_left2 ~f ~init [a1; ...; an] [b1; ...; bn] is f (... (f (f init a1 b1) a2 b2) ...) an bn.
fold_right2 ~f [a1; ...; an] [b1; ...; bn] ~init is f a1 b1 (f a2 b2 (... (f an bn init) ...)).
for_all ~f [a1; ...; an] checks if all elements of the list satisfy the predicate f. That is, it returns (f a1) && (f a2) && ... && (f an) for a non-empty list and true if the list is empty.
exists ~f [a1; ...; an] checks if at least one element of the list satisfies the predicate f. That is, it returns (f a1) || (f a2) || ... || (f an) for a non-empty list and false if the list is empty.
Same as for_all, but for a two-argument predicate.
Same as exists, but for a two-argument predicate.
Same as mem, but uses physical equality instead of structural equality to compare list elements.
find ~f l returns the first element of the list l that satisfies the predicate f.
Same as filter, but the predicate is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
partition ~f l returns a pair of lists (l1, l2), where l1 is the list of all the elements of l that satisfy the predicate f, and l2 is the list of all the elements of l that do not satisfy f. The order of the elements in the input list is preserved.
Same as assoc, but uses physical equality instead of structural equality to compare keys.
Same as mem_assoc, but uses physical equality instead of structural equality to compare keys.
Same as remove_assoc, but uses physical equality instead of structural equality to compare keys. Not tail-recursive.
Sort a list in increasing order according to a comparison function. The comparison function must return 0 if its arguments compare as equal, a positive integer if the first is greater, and a negative integer if the first is smaller (see Array.sort for a complete specification). For example, Stdlib.compare is a suitable comparison function. The resulting list is sorted in increasing order. sort is guaranteed to run in constant heap space (in addition to the size of the result list) and logarithmic stack space.
The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space.
Same as 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.
Same as sort or stable_sort, whichever is faster on typical input.
Merge two lists: Assuming that l1 and l2 are sorted according to the comparison function cmp, merge ~cmp l1 l2 will return a sorted list containing 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).
Safe version of List.append. Concatenate two lists.
cons_maybe (Some x) l is x :: l. cons_maybe None l is l.
Safe version of List.filter. filter 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.
Safe version of fold_right. fold_right f [a1; ...; an] b is f a1 (f a2 (... (f an b) ...)).
Fold until a stop condition via ('a, `Stop) is indicated by the accumulator.
fold_map ~f ~init l is a fold_left-like function, but it also maps the list to another list.
fold_map_i f init l is a foldi-like function, but it also maps the list to another list.
fold_on_map ~f ~reduce init l combines map f and fold_left reduce init in one operation.
scan_left ~f ~init l returns the list [init; f init x0; f (f init x0) x1; ...] where x0, x1, etc. are the elements of l.
val fold_map2 :
f:('acc -> 'a -> 'b -> 'acc * 'c) ->
init:'acc ->
'a list ->
'b list ->
'acc * 'c listfold_map2 is to fold_map what List.map2 is to List.map.
val fold_filter_map :
f:('acc -> 'a -> 'acc * 'b option) ->
init:'acc ->
'a list ->
'acc * 'b listfold_filter_map ~f ~init l is a fold_left-like function, but also generates a list of output in a way similar to filter_map.
val fold_filter_map_i :
f:('acc -> int -> 'a -> 'acc * 'b option) ->
init:'acc ->
'a list ->
'acc * 'b listfold_filter_map_i f init l is a foldi-like function, but also generates a list of output in a way similar to filter_map.
val fold_flat_map :
f:('acc -> 'a -> 'acc * 'b list) ->
init:'acc ->
'a list ->
'acc * 'b listfold_flat_map f acc l is a fold_left-like function, but it also maps the list to a list of lists that is then flatten'd.
val fold_flat_map_i :
f:('acc -> int -> 'a -> 'acc * 'b list) ->
init:'acc ->
'a list ->
'acc * 'b listfold_flat_map_i f acc l is a fold_left-like function, but it also maps the list to a list of lists that is then flatten'd.
count p l counts how many elements of l satisfy predicate p.
Like List.combine but tail-recursive. Transform a pair of lists into a list of pairs: combine [a1; ...; an] [b1; ...; bn] is [(a1,b1); ...; (an,bn)].
A tail-recursive version of List.split. Transform a list of pairs into a pair of lists: split [(a1,b1); ...; (an,bn)] is ([a1; ...; an], [b1; ...; bn]).
Equivalent to compare (length l1) (length l2) but more efficient. Compare the lengths of two lists.
Equivalent to compare (length l) x but more efficient. Compare the length of a list to an integer.
Map and flatten at the same time (safe). Evaluation order is not guaranteed.
Map with index and flatten at the same time (safe). Evaluation order is not guaranteed.
Cartesian product of the two lists, with the given combinator.
Fold on the cartesian product.
Produce the cartesian product of this list of lists, by returning all the ways of picking one element per sublist. NOTE the order of the returned list is unspecified. For example:
# cartesian_product [[1;2];[3];[4;5;6]] |> sort =
[[1;3;4];[1;3;5];[1;3;6];[2;3;4];[2;3;5];[2;3;6]];;
# cartesian_product [[1;2];[];[4;5;6]] = [];;
# cartesian_product [[1;2];[3];[4];[5];[6]] |> sort =
[[1;3;4;5;6];[2;3;4;5;6]];;invariant: cartesian_product l = map_product id l.
map_product_l f l maps each element of l to a list of objects of type 'b using f. We obtain [l1;l2;...;ln] where length l=n and li : 'b list. Then, it returns all the ways of picking exactly one element per li.
All pairs of distinct positions of the list. list_diagonal l will return the list of List.nth i l, List.nth j l if i < j.
val partition_map :
f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) ->
'a list ->
'b list * 'c listpartition_map ~f l maps f on l and gather results in lists:
f x = `Left y, adds y to the first list.f x = `Right z, adds z to the second list.f x = `Drop, ignores x.Group equal elements, regardless of their order of appearance. precondition: for any x and y, if eq x y then hash x=hash y must hold.
join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.
val join_by :
?eq:('key -> 'key -> bool) ->
?hash:('key -> int) ->
('a -> 'key) ->
('b -> 'key) ->
merge:('key -> 'a -> 'b -> 'c option) ->
'a t ->
'b t ->
'c tjoin key1 key2 ~merge is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.
val join_all_by :
?eq:('key -> 'key -> bool) ->
?hash:('key -> int) ->
('a -> 'key) ->
('b -> 'key) ->
merge:('key -> 'a list -> 'b list -> 'c option) ->
'a t ->
'b t ->
'c tjoin_all_by key1 key2 ~merge is a binary operation that takes two sequences a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:
l1 of elements of a that map to kl2 of elements of b that map to kmerge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.val group_join_by :
?eq:('a -> 'a -> bool) ->
?hash:('a -> int) ->
('b -> 'a) ->
'a t ->
'b t ->
('a * 'b list) tgroup_join_by key2 associates to every element x of the first sequence, all the elements y of the second sequence such that eq x (key y). Elements of the first sequences without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.
val sublists_of_len :
?last:('a list -> 'a list option) ->
?offset:int ->
len:int ->
'a list ->
'a list listsublists_of_len n l returns sub-lists of l that have length n. By default, these sub-lists are non overlapping: sublists_of_len 2 [1;2;3;4;5;6] returns [1;2]; [3;4]; [5;6].
Examples:
sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]].sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5].sublists_of_len 3 ~last:CCOpt.return [1;2;3;4] = [1;2;3];[4].sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]].Insert the first argument between every element of the list.
interleave [x1…xn] [y1…ym] is x1,y1,x2,y2,… and finishes with the suffix of the longest list.
take_drop n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n.
take_while ~f l returns the longest prefix of l for which f is true.
drop_while ~f l drops the longest prefix of l for which f is true.
take_drop_while p l = take_while p l, drop_while p l.
last n l takes the last n elements of l (or less if l doesn't have that many elements).
find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p.
find_map ~f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None.
Like find_map, but also pass the index to the predicate function.
find_idx p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None.
remove ~key l removes every instance of key from l. Tail-recursive.
filter_map ~f l is the sublist of l containing only elements for which f returns Some e. Map and remove elements at the same time.
keep_some l retains only elements of the form Some x. Like filter_map CCFun.id.
all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.
all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).
Merge elements from both sorted list.
Sort the list and remove duplicate elements.
sorted_merge_uniq l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
is_sorted l returns true iff l is sorted (according to given order).
sorted_insert x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
uniq_succ l removes duplicate elements that occur one next to the other. Examples: uniq_succ [1;2;1] = [1;2;1]. uniq_succ [1;1;2] = [1;2].
group_succ ~eq l groups together consecutive elements that are equal according to eq.
Like map, but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
Like iter, but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
Like fold but it also passes in the index of each element to the folded function. Tail-recursive.
Fold on two lists, with index.
Get by index in the list. If the index is negative, it will get element starting from the end of the list.
Set i-th element (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.
Insert at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.
Remove element at given index. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
add_nodup x set adds x to set if it was not already present. Linear time.
remove_one x set removes one occurrence of x from set. Linear time.
Remove duplicates w.r.t the equality predicate. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.
List union. Complexity is product of length of inputs.
List intersection. Complexity is product of length of inputs.
range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.
range i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.
Like range but the second bound is excluded. For instance range' 0 5 = [0;1;2;3;4].
Like Assoc.remove.
Randomly choose an element in the list.
val to_string :
?start:string ->
?stop:string ->
?sep:string ->
('a -> string) ->
'a t ->
stringto_string ~start ~stop ~sep item_to_string l print l to a string using sep as a separator between elements of l.
Build a list from a given iter. In the result, elements appear in the same order as they did in the source iter.
Build a list from a given Seq.t. In the result, elements appear in the same order as they did in the source seq.
Build a list from a given gen. In the result, elements appear in the same order as they did in the source gen.
Build a list from a given klist. In the result, elements appear in the same order as they did in the source klist.
It is convenient to openCCList.Infix to access the infix operators without cluttering the scope too much.
Let operators on OCaml >= 4.08.0, nothing otherwise