diff --git a/dev/containers/CCList/index.html b/dev/containers/CCList/index.html index 6d512ca8..062d3ea9 100644 --- a/dev/containers/CCList/index.html +++ b/dev/containers/CCList/index.html @@ -3,7 +3,7 @@ [[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.

since
1.2, but only
since
2.2 with labels
val map_product_l : ('a -> 'b list) -> 'a list -> 'b list list

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.

since
1.2, but only
since
2.2 with labels
val diagonal : 'a t -> ('a * 'a) t

diagonal l returns all pairs of distinct positions of the list l, that is the list of List.nth i l, List.nth j l if i < j.

val partition_map_either : ('a -> ('b'c) CCEither.t) -> 'a list -> 'b list * 'c list

partition_map_either f l maps f on l and gather results in lists:

since
3.3
val partition_filter_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c list

partition_filter_map f l maps f on l and gather results in lists:

since
0.11
val partition_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c list
deprecated

use partition_filter_map instead

val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

group_by ?hash ?eq l groups 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.

since
2.3
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

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.

since
2.3
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 t

join_by ?eq ?hash key1 key2 ~merge la lb 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.

since
2.3
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 t

join_all_by ?eq ?hash key1 key2 ~merge la lb 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:

since
2.3
val group_join_by : ?⁠eq:('a -> 'a -> bool) -> ?⁠hash:('a -> int) -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by ?eq ?hash key la lb 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.

since
2.3
val sublists_of_len : ?⁠last:('a list -> 'a list option) -> ?⁠offset:int -> int -> 'a list -> 'a list list

sublists_of_len ?last ?offset 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:

parameter offset

the number of elements skipped between two consecutive sub-lists. By default it is n. If offset < n, the sub-lists will overlap; if offset > n, some elements will not appear at all.

parameter last

if provided and the last group of elements g is such that length g < n, last g is called. If last g = Some g', g' is appended; otherwise g is dropped. If last = CCOpt.return, it will simply keep the last group. By default, last = fun _ -> None, i.e. the last group is dropped if shorter than n.

raises Invalid_argument

if offset <= 0 or n <= 0. See CCList.sublists_of_len for more details.

since
1.0, but only
since
1.5 with labels
val chunks : int -> 'a list -> 'a list list

chunks n l returns consecutives chunks of size at most n from l. Each item of l will occur in exactly one chunk. Only the last chunk might be of length smaller than n. Invariant: (chunks n l |> List.flatten) = l.

since
3.2
val intersperse : 'a -> 'a list -> 'a list

intersperse x l inserts the element x between adjacent elements of the list l.

since
2.1, but only
since
2.2 with labels
val interleave : 'a list -> 'a list -> 'a list

interleave [x1…xn] [y1…ym] is [x1;y1;x2;y2;…] and finishes with the suffix of the longest list.

since
2.1, but only
since
2.2 with labels
val pure : 'a -> 'a t

pure x is return x.

val mguard : bool -> unit t

mguard c is pure () if c is true, [] otherwise. This is useful to define a list by comprehension, e.g.:

# let square_even xs =
+[[1;3;4;5;6];[2;3;4;5;6]];;

invariant: cartesian_product l = map_product id l.

since
1.2, but only
since
2.2 with labels
val map_product_l : ('a -> 'b list) -> 'a list -> 'b list list

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.

since
1.2, but only
since
2.2 with labels
val diagonal : 'a t -> ('a * 'a) t

diagonal l returns all pairs of distinct positions of the list l, that is the list of List.nth i l, List.nth j l if i < j.

val partition_map_either : ('a -> ('b'c) CCEither.t) -> 'a list -> 'b list * 'c list

partition_map_either f l maps f on l and gather results in lists:

since
3.3
val partition_filter_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c list

partition_filter_map f l maps f on l and gather results in lists:

since
3.3
val partition_map : ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> 'a list -> 'b list * 'c list
deprecated

use partition_filter_map instead

since
0.11
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

group_by ?hash ?eq l groups 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.

since
2.3
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

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.

since
2.3
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 t

join_by ?eq ?hash key1 key2 ~merge la lb 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.

since
2.3
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 t

join_all_by ?eq ?hash key1 key2 ~merge la lb 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:

since
2.3
val group_join_by : ?⁠eq:('a -> 'a -> bool) -> ?⁠hash:('a -> int) -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by ?eq ?hash key la lb 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.

since
2.3
val sublists_of_len : ?⁠last:('a list -> 'a list option) -> ?⁠offset:int -> int -> 'a list -> 'a list list

sublists_of_len ?last ?offset 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:

parameter offset

the number of elements skipped between two consecutive sub-lists. By default it is n. If offset < n, the sub-lists will overlap; if offset > n, some elements will not appear at all.

parameter last

if provided and the last group of elements g is such that length g < n, last g is called. If last g = Some g', g' is appended; otherwise g is dropped. If last = CCOpt.return, it will simply keep the last group. By default, last = fun _ -> None, i.e. the last group is dropped if shorter than n.

raises Invalid_argument

if offset <= 0 or n <= 0. See CCList.sublists_of_len for more details.

since
1.0, but only
since
1.5 with labels
val chunks : int -> 'a list -> 'a list list

chunks n l returns consecutives chunks of size at most n from l. Each item of l will occur in exactly one chunk. Only the last chunk might be of length smaller than n. Invariant: (chunks n l |> List.flatten) = l.

since
3.2
val intersperse : 'a -> 'a list -> 'a list

intersperse x l inserts the element x between adjacent elements of the list l.

since
2.1, but only
since
2.2 with labels
val interleave : 'a list -> 'a list -> 'a list

interleave [x1…xn] [y1…ym] is [x1;y1;x2;y2;…] and finishes with the suffix of the longest list.

since
2.1, but only
since
2.2 with labels
val pure : 'a -> 'a t

pure x is return x.

val mguard : bool -> unit t

mguard c is pure () if c is true, [] otherwise. This is useful to define a list by comprehension, e.g.:

# let square_even xs =
       let* x = xs in
       let* () = mguard (x mod 2 = 0) in
       return @@ x * x;;