diff --git a/dev/containers/CCArray/Infix/index.html b/dev/containers/CCArray/Infix/index.html index 6f1dbabc..70089d96 100644 --- a/dev/containers/CCArray/Infix/index.html +++ b/dev/containers/CCArray/Infix/index.html @@ -1,2 +1,2 @@ -
CCArray.Infixval (--) : int -> int -> int tx -- y creates an array containing integers in the range x .. y. Bounds included.
val (--^) : int -> int -> int tx --^ y creates an array containing integers in the range x .. y. Right bound excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a arrayCCArray.Infixval (--) : int -> int -> int tx -- y creates an array containing integers in the range x .. y. Bounds included.
val (--^) : int -> int -> int tx --^ y creates an array containing integers in the range x .. y. Right bound excluded.
CCArrayArray utils
include module type of CCShimsArray_include module type of struct include Stdlib.Array endval empty : 'a tempty is the empty array, physically equal to [||].
equal eq a1 a2 is true if the lengths of a1 and a2 are the same and if their corresponding elements test equal, using eq.
compare cmp a1 a2 compares arrays a1 and a2 using the function comparison cmp.
val swap : 'a t -> int -> int -> unitswap a i j swaps elements at indices i and j.
val get_safe : 'a t -> int -> 'a optionget_safe a i returns Some a.(i) if i is a valid index.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init a computes f (… (f (f init a.(0)) a.(1)) …) a.(n-1), where n is the length of the array a. Same as Array.fold_left
val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'afoldi f init a is just like fold, but it also passes in the index of each element as the second argument to the folded function f.
val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'afold_while f init a folds left on array a until a stop condition via ('a, `Stop) is indicated by the accumulator.
fold_map f init a is a fold_left-like function, but it also maps the array to another array.
scan_left f init a returns the array [|init; f init x0; f (f init a.(0)) a.(1); …|] .
val reverse_in_place : 'a t -> unitreverse_in_place a reverses the array a in place.
val sorted : ('a -> 'a -> int) -> 'a t -> 'a arraysorted f a makes a copy of a and sorts it with f.
val sort_indices : ('a -> 'a -> int) -> 'a t -> int arraysort_indices f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of sorted f a appears in a. a is not modified.
In other words, map (fun i -> a.(i)) (sort_indices f a) = sorted f a. sort_indices yields the inverse permutation of sort_ranking.
val sort_ranking : ('a -> 'a -> int) -> 'a t -> int arraysort_ranking f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of a appears in sorted f a. a is not modified.
In other words, map (fun i -> (sorted f a).(i)) (sort_ranking f a) = a. sort_ranking yields the inverse permutation of sort_indices.
In the absence of duplicate elements in a, we also have lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i).
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ~eq x a return true if x is present in a. Linear time.
val find_map : ('a -> 'b option) -> 'a t -> 'b optionfind_map f a returns Some y if there is an element x such that f x = Some y. Otherwise returns None.
val find_map_i : (int -> 'a -> 'b option) -> 'a t -> 'b optionfind_map_i f a is like find_map, but the index of the element is also passed to the predicate function f.
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) optionfind_idx f a returns Some (i,x) where x is the i-th element of a, and f x holds. Otherwise returns None.
lookup ~cmp key a lookups the index of some key key in a sorted array a. Undefined behavior if the array a is not sorted wrt ~cmp. Complexity: O(log (n)) (dichotomic search).
val bsearch : cmp:('a -> 'a -> int) ->
-'a -> 'a t -> [ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]bsearch ~cmp key a finds the index of the object key in the array a, provided a is sorted using cmp. If the array is not sorted, the result is not specified (may raise Invalid_argument).
Complexity: O(log n) where n is the length of the array a (dichotomic search).
for_all2 f [|a1; …; an|] [|b1; …; bn|] is true if each pair of elements ai bi satisfies the predicate f. That is, it returns (f a1 b1) && (f a2 b2) && … && (f an bn).
exists2 f [|a1; …; an|] [|b1; …; bn|] is true if any pair of elements ai bi satisfies the predicate f. That is, it returns (f a1 b1) || (f a2 b2) || … || (f an bn).
fold2 f init a b fold on two arrays a and b stepwise. It computes f (… (f init a1 b1) …) an bn.
val shuffle : 'a t -> unitshuffle a randomly shuffles the array a, in place.
val shuffle_with : Stdlib.Random.State.t -> 'a t -> unitshuffle_with rs a randomly shuffles the array a (like shuffle) but a specialized random state rs is used to control the random numbers being produced during shuffling (for reproducibility).
val random_choose : 'a t -> 'a random_genrandom_choose a rs randomly chooses an element of a.
to_string ~sep item_to_string a print a to a string using sep as a separator between elements of a.
to_iter a returns an iter of the elements of an array a. The input array a is shared with the sequence and modification of it will result in modification of the iterator.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq a returns a Seq.t of the elements of an array a. The input array a is shared with the sequence and modification of it will result in modification of the sequence. Renamed from to_std_seq since 3.0.
val pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> 'a t printerpp ~pp_start ~pp_stop ~pp_sep pp_item ppf a formats the array a on ppf. Each element is formatted with pp_item, pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").
val pp_i : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> (int -> 'a printer) -> 'a t printerpp_i ~pp_start ~pp_stop ~pp_sep pp_item ppf a prints the array a on ppf. The printing function pp_item is giving both index and element. pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").
filter f a filters elements out of the array a. Only the elements satisfying the given predicate f will be kept.
filter_map f [|a1; …; an|] calls (f a1) … (f an) and returns an array b consisting of all elements bi such as f ai = Some bi. When f returns None, the corresponding element of a is discarded.
monoid_product f a b passes all combinaisons of tuples from the two arrays a and b to the function f.
flat_map f a transforms each element of a into an array, then flattens.
val except_idx : 'a t -> int -> 'a listexcept_idx a i removes the element of a at given index i, and returns the list of the other elements.
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genmodule type MONO_ARRAY = sig ... endval sort_generic : (module MONO_ARRAY with type elt = 'elt and type t = 'arr) -> cmp:('elt -> 'elt -> int)
--> 'arr -> unitsort_generic (module M) ~cmp a sorts the array a, without allocating (eats stack space though). Performance might be lower than Array.sort.
It is convenient to open CCArray.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endinclude module type of Infixval (--) : int -> int -> int tx -- y creates an array containing integers in the range x .. y. Bounds included.
val (--^) : int -> int -> int tx --^ y creates an array containing integers in the range x .. y. Right bound excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a arrayCCArrayArray utils
include module type of struct include Stdlib.Array endval empty : 'a tempty is the empty array, physically equal to [||].
equal eq a1 a2 is true if the lengths of a1 and a2 are the same and if their corresponding elements test equal, using eq.
compare cmp a1 a2 compares arrays a1 and a2 using the function comparison cmp.
val swap : 'a t -> int -> int -> unitswap a i j swaps elements at indices i and j.
val get_safe : 'a t -> int -> 'a optionget_safe a i returns Some a.(i) if i is a valid index.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init a computes f (… (f (f init a.(0)) a.(1)) …) a.(n-1), where n is the length of the array a. Same as Array.fold_left
val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'afoldi f init a is just like fold, but it also passes in the index of each element as the second argument to the folded function f.
val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'afold_while f init a folds left on array a until a stop condition via ('a, `Stop) is indicated by the accumulator.
fold_map f init a is a fold_left-like function, but it also maps the array to another array.
scan_left f init a returns the array [|init; f init x0; f (f init a.(0)) a.(1); …|] .
val reverse_in_place : 'a t -> unitreverse_in_place a reverses the array a in place.
val sorted : ('a -> 'a -> int) -> 'a t -> 'a arraysorted f a makes a copy of a and sorts it with f.
val sort_indices : ('a -> 'a -> int) -> 'a t -> int arraysort_indices f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of sorted f a appears in a. a is not modified.
In other words, map (fun i -> a.(i)) (sort_indices f a) = sorted f a. sort_indices yields the inverse permutation of sort_ranking.
val sort_ranking : ('a -> 'a -> int) -> 'a t -> int arraysort_ranking f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of a appears in sorted f a. a is not modified.
In other words, map (fun i -> (sorted f a).(i)) (sort_ranking f a) = a. sort_ranking yields the inverse permutation of sort_indices.
In the absence of duplicate elements in a, we also have lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i).
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ~eq x a return true if x is present in a. Linear time.
val find_map : ('a -> 'b option) -> 'a t -> 'b optionfind_map f a returns Some y if there is an element x such that f x = Some y. Otherwise returns None.
val find_map_i : (int -> 'a -> 'b option) -> 'a t -> 'b optionfind_map_i f a is like find_map, but the index of the element is also passed to the predicate function f.
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) optionfind_idx f a returns Some (i,x) where x is the i-th element of a, and f x holds. Otherwise returns None.
lookup ~cmp key a lookups the index of some key key in a sorted array a. Undefined behavior if the array a is not sorted wrt ~cmp. Complexity: O(log (n)) (dichotomic search).
val bsearch : cmp:('a -> 'a -> int) ->
+'a -> 'a t -> [ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]bsearch ~cmp key a finds the index of the object key in the array a, provided a is sorted using cmp. If the array is not sorted, the result is not specified (may raise Invalid_argument).
Complexity: O(log n) where n is the length of the array a (dichotomic search).
for_all2 f [|a1; …; an|] [|b1; …; bn|] is true if each pair of elements ai bi satisfies the predicate f. That is, it returns (f a1 b1) && (f a2 b2) && … && (f an bn).
exists2 f [|a1; …; an|] [|b1; …; bn|] is true if any pair of elements ai bi satisfies the predicate f. That is, it returns (f a1 b1) || (f a2 b2) || … || (f an bn).
fold2 f init a b fold on two arrays a and b stepwise. It computes f (… (f init a1 b1) …) an bn.
val shuffle : 'a t -> unitshuffle a randomly shuffles the array a, in place.
val shuffle_with : Stdlib.Random.State.t -> 'a t -> unitshuffle_with rs a randomly shuffles the array a (like shuffle) but a specialized random state rs is used to control the random numbers being produced during shuffling (for reproducibility).
val random_choose : 'a t -> 'a random_genrandom_choose a rs randomly chooses an element of a.
of_list_map f l applies the function f to all the elements of the list l and builds an array with the results returned by f. The result is equivalent to map f (Array.of_list l).
to_string ~sep item_to_string a print a to a string using sep as a separator between elements of a.
to_iter a returns an iter of the elements of an array a. The input array a is shared with the sequence and modification of it will result in modification of the iterator.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq a returns a Seq.t of the elements of an array a. The input array a is shared with the sequence and modification of it will result in modification of the sequence. Renamed from to_std_seq since 3.0.
val pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> 'a t printerpp ~pp_start ~pp_stop ~pp_sep pp_item ppf a formats the array a on ppf. Each element is formatted with pp_item, pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").
val pp_i : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> (int -> 'a printer) -> 'a t printerpp_i ~pp_start ~pp_stop ~pp_sep pp_item ppf a prints the array a on ppf. The printing function pp_item is giving both index and element. pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").
filter f a filters elements out of the array a. Only the elements satisfying the given predicate f will be kept.
filter_map f [|a1; …; an|] calls (f a1) … (f an) and returns an array b consisting of all elements bi such as f ai = Some bi. When f returns None, the corresponding element of a is discarded.
monoid_product f a b passes all combinaisons of tuples from the two arrays a and b to the function f.
flat_map f a transforms each element of a into an array, then flattens.
val except_idx : 'a t -> int -> 'a listexcept_idx a i removes the element of a at given index i, and returns the list of the other elements.
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genmodule type MONO_ARRAY = sig ... endval sort_generic : (module MONO_ARRAY with type elt = 'elt and type t = 'arr) -> cmp:('elt -> 'elt -> int)
+-> 'arr -> unitsort_generic (module M) ~cmp a sorts the array a, without allocating (eats stack space though). Performance might be lower than Array.sort.
It is convenient to open CCArray.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endCCArrayLabels.Infixval (--) : int -> int -> int tx -- y creates an array containing integers in the range x .. y. Bounds included.
val (--^) : int -> int -> int tx --^ y creates an array containing integers in the range x .. y. Right bound excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a arrayCCArrayLabels.Infixval (--) : int -> int -> int tx -- y creates an array containing integers in the range x .. y. Bounds included.
val (--^) : int -> int -> int tx --^ y creates an array containing integers in the range x .. y. Right bound excluded.
CCArrayLabelsArray utils (Labeled version of CCArray)
include module type of CCShimsArrayLabels_include module type of Stdlib.ArrayLabels with module Floatarray = Stdlib.Array.Floatarraymodule Floatarray : sig ... endval empty : 'a tempty is the empty array, physically equal to ||.
equal eq a1 a2 is true if the lengths of a1 and a2 are the same and if their corresponding elements test equal, using eq.
compare cmp a1 a2 compares arrays a1 and a2 using the function comparison cmp.
val swap : 'a t -> int -> int -> unitswap a i j swaps elements at indices i and j.
val get_safe : 'a t -> int -> 'a optionget_safe a i returns Some a.(i) if i is a valid index.
val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'afold ~f ~init a computes f (… (f (f init a.(0)) a.(1)) …) a.(n-1), where n is the length of the array a. Same as ArrayLabels.fold_left
val foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'afoldi ~f ~init a is just like fold, but it also passes in the index of each element as the second argument to the folded function f.
val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'afold_while ~f ~init a folds left on array a until a stop condition via ('a, `Stop) is indicated by the accumulator.
fold_map ~f ~init a is a fold_left-like function, but it also maps the array to another array.
scan_left ~f ~init a returns the array [|init; f init x0; f (f init a.(0)) a.(1); …|] .
val reverse_in_place : 'a t -> unitreverse_in_place a reverses the array a in place.
val sorted : f:('a -> 'a -> int) -> 'a t -> 'a arraysorted ~f a makes a copy of a and sorts it with f.
val sort_indices : f:('a -> 'a -> int) -> 'a t -> int arraysort_indices ~f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of sorted f a appears in a. a is not modified.
In other words, map (fun i -> a.(i)) (sort_indices f a) = sorted f a. sort_indices yields the inverse permutation of sort_ranking.
val sort_ranking : f:('a -> 'a -> int) -> 'a t -> int arraysort_ranking ~f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of a appears in sorted f a. a is not modified.
In other words, map (fun i -> (sorted f a).(i)) (sort_ranking f a) = a. sort_ranking yields the inverse permutation of sort_indices.
In the absence of duplicate elements in a, we also have lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i).
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ~eq x a return true if x is present in a. Linear time.
val find_map : f:('a -> 'b option) -> 'a t -> 'b optionfind_map ~f a returns Some y if there is an element x such that f x = Some y. Otherwise returns None.
val find_map_i : f:(int -> 'a -> 'b option) -> 'a t -> 'b optionfind_map_i ~f a is like find_map, but the index of the element is also passed to the predicate function f.
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) optionfind_idx ~f a returns Some (i,x) where x is the i-th element of a, and f x holds. Otherwise returns None.
lookup ~cmp ~key a lookups the index of some key key in a sorted array a. Undefined behavior if the array a is not sorted wrt cmp. Complexity: O(log (n)) (dichotomic search).
val bsearch : cmp:('a -> 'a -> int) -> key:'a ->
+CCArrayLabels (containers.CCArrayLabels) Module CCArrayLabels
Array utils (Labeled version of CCArray)
Arrays
include module type of Stdlib.ArrayLabels with module Floatarray = Stdlib.Array.Floatarray
module Floatarray : sig ... endval empty : 'a tempty is the empty array, physically equal to ||.
equal eq a1 a2 is true if the lengths of a1 and a2 are the same and if their corresponding elements test equal, using eq.
compare cmp a1 a2 compares arrays a1 and a2 using the function comparison cmp.
val swap : 'a t -> int -> int -> unitswap a i j swaps elements at indices i and j.
val get_safe : 'a t -> int -> 'a optionget_safe a i returns Some a.(i) if i is a valid index.
val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'afold ~f ~init a computes f (… (f (f init a.(0)) a.(1)) …) a.(n-1), where n is the length of the array a. Same as ArrayLabels.fold_left
val foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'afoldi ~f ~init a is just like fold, but it also passes in the index of each element as the second argument to the folded function f.
val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'afold_while ~f ~init a folds left on array a until a stop condition via ('a, `Stop) is indicated by the accumulator.
fold_map ~f ~init a is a fold_left-like function, but it also maps the array to another array.
scan_left ~f ~init a returns the array [|init; f init x0; f (f init a.(0)) a.(1); …|] .
val reverse_in_place : 'a t -> unitreverse_in_place a reverses the array a in place.
val sorted : f:('a -> 'a -> int) -> 'a t -> 'a arraysorted ~f a makes a copy of a and sorts it with f.
val sort_indices : f:('a -> 'a -> int) -> 'a t -> int arraysort_indices ~f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of sorted f a appears in a. a is not modified.
In other words, map (fun i -> a.(i)) (sort_indices f a) = sorted f a. sort_indices yields the inverse permutation of sort_ranking.
val sort_ranking : f:('a -> 'a -> int) -> 'a t -> int arraysort_ranking ~f a returns a new array b, with the same length as a, such that b.(i) is the index at which the i-th element of a appears in sorted f a. a is not modified.
In other words, map (fun i -> (sorted f a).(i)) (sort_ranking f a) = a. sort_ranking yields the inverse permutation of sort_indices.
In the absence of duplicate elements in a, we also have lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i).
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ~eq x a return true if x is present in a. Linear time.
val find_map : f:('a -> 'b option) -> 'a t -> 'b optionfind_map ~f a returns Some y if there is an element x such that f x = Some y. Otherwise returns None.
val find_map_i : f:(int -> 'a -> 'b option) -> 'a t -> 'b optionfind_map_i ~f a is like find_map, but the index of the element is also passed to the predicate function f.
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) optionfind_idx ~f a returns Some (i,x) where x is the i-th element of a, and f x holds. Otherwise returns None.
lookup ~cmp ~key a lookups the index of some key key in a sorted array a. Undefined behavior if the array a is not sorted wrt cmp. Complexity: O(log (n)) (dichotomic search).
val bsearch : cmp:('a -> 'a -> int) -> key:'a ->
'a t -> [ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]bsearch ~cmp ~key a finds the index of the object key in the array a, provided a is sorted using cmp. If the array is not sorted, the result is not specified (may raise Invalid_argument).
Complexity: O(log n) where n is the length of the array a (dichotomic search).
for_all2 ~f [|a1; …; an|] [|b1; …; bn|] is true if each pair of elements ai bi satisfies the predicate f. That is, it returns (f a1 b1) && (f a2 b2) && … && (f an bn).
exists2 ~f [|a1; …; an|] [|b1; …; bn|] is true if any pair of elements ai bi satisfies the predicate f. That is, it returns (f a1 b1) || (f a2 b2) || … || (f an bn).
fold2 ~f ~init a b fold on two arrays a and b stepwise. It computes f (… (f init a1 b1) …) an bn.
iter2 ~f a b iterates on the two arrays a and b stepwise. It is equivalent to f a0 b0; …; f a.(length a - 1) b.(length b - 1); ().
val shuffle : 'a t -> unitshuffle a randomly shuffles the array a, in place.
val shuffle_with : Stdlib.Random.State.t -> 'a t -> unitshuffle_with rs a randomly shuffles the array a (like shuffle) but a specialized random state rs is used to control the random numbers being produced during shuffling (for reproducibility).
val random_choose : 'a t -> 'a random_genrandom_choose a rs randomly chooses an element of a.
to_string ~sep item_to_string a print a to a string using sep as a separator between elements of a.
to_iter a returns an iter of the elements of an array a. The input array a is shared with the sequence and modification of it will result in modification of the iterator.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq a returns a Seq.t of the elements of an array a. The input array a is shared with the sequence and modification of it will result in modification of the sequence. Renamed from to_std_seq since 3.0.
IO
val pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> 'a t printerpp ~pp_start ~pp_stop ~pp_sep pp_item ppf a formats the array a on ppf. Each element is formatted with pp_item, pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").
val pp_i : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> (int -> 'a printer) -> 'a t printerpp_i ~pp_start ~pp_stop ~pp_sep pp_item ppf a prints the array a on ppf. The printing function pp_item is giving both index and element. pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").
map2 ~f a b applies function f to all elements of a and b, and builds an array with the results returned by f: [| f a.(0) b.(0); …; f a.(length a - 1) b.(length b - 1)|].
filter ~f a filters elements out of the array a. Only the elements satisfying the given predicate f will be kept.
filter_map ~f [|a1; …; an|] calls (f a1) … (f an) and returns an array b consisting of all elements bi such as f ai = Some bi. When f returns None, the corresponding element of a is discarded.
monoid_product ~f a b passes all combinaisons of tuples from the two arrays a and b to the function f.
flat_map ~f a transforms each element of a into an array, then flattens.
val except_idx : 'a t -> int -> 'a listexcept_idx a i removes the element of a at given index i, and returns the list of the other elements.
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genGeneric Functions
module type MONO_ARRAY = sig ... endval sort_generic : (module MONO_ARRAY with type elt = 'elt and type t = 'arr) -> cmp:('elt -> 'elt -> int)
--> 'arr -> unitsort_generic (module M) ~cmp a sorts the array a, without allocating (eats stack space though). Performance might be lower than Array.sort.
Infix Operators
It is convenient to open CCArray.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endinclude module type of Infix
val (--) : int -> int -> int tx -- y creates an array containing integers in the range x .. y. Bounds included.
val (--^) : int -> int -> int tx --^ y creates an array containing integers in the range x .. y. Right bound excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a array
\ No newline at end of file
+-> 'arr -> unitsort_generic (module M) ~cmp a sorts the array a, without allocating (eats stack space though). Performance might be lower than Array.sort.
It is convenient to open CCArray.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endCCFunBasic operations on Functions
include module type of CCShimsFun_compose_binop f g is fun x y -> g (f x) (f y). Example (partial order): List.sort (compose_binop fst CCInt.compare) [1, true; 2, false; 1, false].
curry f x y is f (x,y). Convert a function which accepts a pair of arguments into a function which accepts two arguments.
uncurry f (x,y) is f x y. Convert a function which accepts a two arguments into a function which accepts a pair of arguments.
tap f x evaluates f x, discards it, then returns x. Useful in a pipeline, for instance:
CCArray.(1 -- 10)
+CCFun (containers.CCFun) Module CCFun
Basic operations on Functions
compose_binop f g is fun x y -> g (f x) (f y). Example (partial order): List.sort (compose_binop fst CCInt.compare) [1, true; 2, false; 1, false].
curry f x y is f (x,y). Convert a function which accepts a pair of arguments into a function which accepts two arguments.
uncurry f (x,y) is f x y. Convert a function which accepts a two arguments into a function which accepts a pair of arguments.
tap f x evaluates f x, discards it, then returns x. Useful in a pipeline, for instance:
CCArray.(1 -- 10)
|> tap CCArray.shuffle
|> tap @@ CCArray.sort Stdlib.compare
Lexicographic combination of comparison functions.
finally ~h f calls f () and returns its result. If it raises, the same exception is raised; in any case, h () is called after f () terminates. If h () raises an exception, then this exception will be passed on and any exception that may have been raised by f () is lost.
finally1 ~h f x is the same as f x, but after the computation, h () is called whether f x rose an exception or not. If h () raises an exception, then this exception will be passed on and any exception that may have been raised by f () is lost.
finally2 ~h f x y is the same as f x y, but after the computation, h () is called whether f x y rose an exception or not. If h () raises an exception, then this exception will be passed on and any exception that may have been raised by f () is lost.
opaque_identity x is like x, but prevents Flambda from using x's definition for optimizing it. (flambda is an optimization/inlining pass in OCaml >= 4.03).
iterate n f is f iterated n times. That is to say, iterate 0 f x is x, iterate 1 f x is f x, iterate 2 f x is f (f x), etc.
Infix
Infix operators.
module Infix : sig ... endinclude module type of Infix
(f %> g) x or (%>) f g x is g (f x). Alias to compose.
Monad
Functions with a fixed domain are monads in their codomain.
\ No newline at end of file
diff --git a/dev/containers/CCInt/index.html b/dev/containers/CCInt/index.html
index 0c145b90..b7f94ce1 100644
--- a/dev/containers/CCInt/index.html
+++ b/dev/containers/CCInt/index.html
@@ -1,2 +1,2 @@
-CCInt (containers.CCInt) Module CCInt
Basic Int functions
include module type of CCShimsInt_
include module type of struct include Stdlib.Int end
val zero : tzero is the integer 0.
val one : tone is the integer 1.
val minus_one : tminus_one is the integer -1.
val max_int : tmax_int is the maximum integer.
val min_int : tmin_int is the minimum integer.
compare x y is the comparison function for integers with the same specification as Stdlib.compare.
val hash : t -> inthash x computes the hash of x.
val sign : t -> intsign x return 0 if x = 0, -1 if x < 0 and 1 if x > 0. Same as compare x 0.
pow base exponent returns base raised to the power of exponent. pow x y = x^y for positive integers x and y. Raises Invalid_argument if x = y = 0 or y < 0.
floor_div x n is integer division rounding towards negative infinity. It satisfies x = m * floor_div x n + rem x n.
val random : int -> t random_genval random_small : t random_genval random_range : int -> int -> t random_genval to_float : t -> floatto_float is the same as float_of_int
val to_string : t -> stringto_string x returns the string representation of the integer x, in signed decimal.
val of_string : string -> t optionof_string s converts the given string s into an integer. Safe version of of_string_exn.
val of_string_exn : string -> tof_string_exn s converts the given string s to an integer. Alias to int_of_string.
val of_float : float -> tof_float x converts the given floating-point number x to an integer. Alias to int_of_float.
val to_string_binary : t -> stringto_string_binary x returns the string representation of the integer x, in binary.
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.
range' i j is like range but the second bound j is excluded. For instance range' 0 5 = Iter.of_list [0;1;2;3;4].
val popcount : t -> intNumber of bits set to 1
Infix Operators
module Infix : sig ... endinclude module type of Infix
\ No newline at end of file
+CCInt (containers.CCInt) Module CCInt
Basic Int functions
include module type of struct include Stdlib.Int end
val zero : tzero is the integer 0.
val one : tone is the integer 1.
val minus_one : tminus_one is the integer -1.
val max_int : tmax_int is the maximum integer.
val min_int : tmin_int is the minimum integer.
compare x y is the comparison function for integers with the same specification as Stdlib.compare.
val hash : t -> inthash x computes the hash of x.
val sign : t -> intsign x return 0 if x = 0, -1 if x < 0 and 1 if x > 0. Same as compare x 0.
pow base exponent returns base raised to the power of exponent. pow x y = x^y for positive integers x and y. Raises Invalid_argument if x = y = 0 or y < 0.
floor_div x n is integer division rounding towards negative infinity. It satisfies x = m * floor_div x n + rem x n.
val random : int -> t random_genval random_small : t random_genval random_range : int -> int -> t random_genval to_float : t -> floatto_float is the same as float_of_int
val to_string : t -> stringto_string x returns the string representation of the integer x, in signed decimal.
val of_string : string -> t optionof_string s converts the given string s into an integer. Safe version of of_string_exn.
val of_string_exn : string -> tof_string_exn s converts the given string s to an integer. Alias to int_of_string.
val of_float : float -> tof_float x converts the given floating-point number x to an integer. Alias to int_of_float.
val to_string_binary : t -> stringto_string_binary x returns the string representation of the integer x, in binary.
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.
range' i j is like range but the second bound j is excluded. For instance range' 0 5 = Iter.of_list [0;1;2;3;4].
val popcount : t -> intNumber of bits set to 1
Infix Operators
module Infix : sig ... endinclude module type of Infix
\ No newline at end of file
diff --git a/dev/containers/CCList/Infix/index.html b/dev/containers/CCList/Infix/index.html
index 3ff3f324..8de11025 100644
--- a/dev/containers/CCList/Infix/index.html
+++ b/dev/containers/CCList/Infix/index.html
@@ -1,9 +1,9 @@
-Infix (containers.CCList.Infix) Module CCList.Infix
val (--) : int -> int -> int ti -- j is the infix alias for range. Bounds included.
val (--^) : int -> int -> int ti --^ j is the infix alias for range'. Second bound j excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a list
include CCShimsMkLetList_.S
(and&) is combine_shortest. It allows to perform a synchronized product between two lists, stopping gently at the shortest. Usable both with let+ and let*.
# let f xs ys zs =
+Infix (containers.CCList.Infix) Module CCList.Infix
val (--) : int -> int -> int ti -- j is the infix alias for range. Bounds included.
val (--^) : int -> int -> int ti --^ j is the infix alias for range'. Second bound j excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
(and&) is combine_shortest. It allows to perform a synchronized product between two lists, stopping gently at the shortest. Usable both with let+ and let*.
# let f xs ys zs =
let+ x = xs
and& y = ys
and& z = zs in
x + y + z;;
val f : int list -> int list -> int list -> int list = <fun>
# f [1;2] [5;6;7] [10;10];;
-- : int list = [16; 18]
\ No newline at end of file
+- : int list = [16; 18]
\ No newline at end of file
diff --git a/dev/containers/CCList/index.html b/dev/containers/CCList/index.html
index 5fa46640..9505c176 100644
--- a/dev/containers/CCList/index.html
+++ b/dev/containers/CCList/index.html
@@ -1,5 +1,5 @@
-CCList (containers.CCList) Module CCList
Complements to List
include module type of Stdlib.List
val empty : 'a tempty is [].
val is_empty : _ t -> boolis_empty l returns true iff l = [].
map f [a0; a1; …; an] applies function f in turn to a0; a1; …; an. Safe version of List.map.
append l1 l2 returns the list that is the concatenation of l1 and l2. Safe version of List.append.
cons' l x is the same as x :: l. This is convenient for fold functions such as List.fold_left or Array.fold_left.
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 l is preserved. Safe version of List.filter.
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'bfold_right f [a1; …; an] b is f a1 (f a2 ( … (f an b) … )). Safe version of List.fold_right.
val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'afold_while f init l folds 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.
reduce f (hd::tl) returns Some (fold_left f hd tl). If l is empty, then None is returned.
reduce_exn is the unsafe version of reduce.
fold_map2 f init l1 l2 is to fold_map what List.map2 is to List.map.
fold_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 : ('acc -> int -> 'a -> 'acc * 'b option) -> '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.
fold_flat_map f init l is a fold_left-like function, but it also maps the list to a list of lists that is then flatten'd.
fold_flat_map_i f init 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.
count_true_false p l returns a pair (int1,int2) where int1 is the number of elements in l that satisfy the predicate p, and int2 the number of elements that do not satisfy p.
val init : int -> (int -> 'a) -> 'a tinit len f is f 0; f 1; …; f (len-1).
combine [a1; …; an] [b1; …; bn] is [(a1,b1); …; (an,bn)]. Transform two lists into a list of pairs. Like List.combine but tail-recursive.
val combine_gen : 'a list -> 'b list -> ('a * 'b) gencombine_shortest [a1; …; am] [b1; …; bn] is [(a1,b1); …; (am,bm)] if m <= n. Like combine but stops at the shortest list rather than raising.
split [(a1,b1); …; (an,bn)] is ([a1; …; an], [b1; …; bn]). Transform a list of pairs into a pair of lists. A tail-recursive version of List.split.
compare cmp l1 l2 compares the two lists l1 and l2 using the given comparison function cmp.
compare_lengths l1 l2 compare the lengths of the two lists l1 and l2. Equivalent to compare (length l1) (length l2) but more efficient.
val compare_length_with : 'a t -> int -> intcompare_length_with l x compares the length of the list l to an integer x. Equivalent to compare (length l) x but more efficient.
equal p l1 l2 returns true if l1 and l2 are equal.
flat_map f l maps and flattens at the same time (safe). Evaluation order is not guaranteed.
flat_map_i f l maps with index and flattens at the same time (safe). Evaluation order is not guaranteed.
flatten [l1]; [l2]; … concatenates a list of lists. Safe version of List.flatten.
product comb l1 l2 computes the cartesian product of the two lists, with the given combinator comb.
fold_product f init l1 l2 applies the function f with the accumulator init on all the pair of elements of l1 and l2. Fold on the cartesian product.
cartesian_product [[l1]; [l2]; …; [ln]] produces 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 =
+CCList (containers.CCList) Module CCList
Complements to List
include module type of Stdlib.List
val empty : 'a tempty is [].
val is_empty : _ t -> boolis_empty l returns true iff l = [].
map f [a0; a1; …; an] applies function f in turn to a0; a1; …; an. Safe version of List.map.
append l1 l2 returns the list that is the concatenation of l1 and l2. Safe version of List.append.
cons' l x is the same as x :: l. This is convenient for fold functions such as List.fold_left or Array.fold_left.
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 l is preserved. Safe version of List.filter.
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'bfold_right f [a1; …; an] b is f a1 (f a2 ( … (f an b) … )). Safe version of List.fold_right.
val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'afold_while f init l folds 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.
reduce f (hd::tl) returns Some (fold_left f hd tl). If l is empty, then None is returned.
reduce_exn is the unsafe version of reduce.
fold_map2 f init l1 l2 is to fold_map what List.map2 is to List.map.
fold_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 : ('acc -> int -> 'a -> 'acc * 'b option) -> '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.
fold_flat_map f init l is a fold_left-like function, but it also maps the list to a list of lists that is then flatten'd.
fold_flat_map_i f init 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.
count_true_false p l returns a pair (int1,int2) where int1 is the number of elements in l that satisfy the predicate p, and int2 the number of elements that do not satisfy p.
val init : int -> (int -> 'a) -> 'a tinit len f is f 0; f 1; …; f (len-1).
combine [a1; …; an] [b1; …; bn] is [(a1,b1); …; (an,bn)]. Transform two lists into a list of pairs. Like List.combine but tail-recursive.
val combine_gen : 'a list -> 'b list -> ('a * 'b) gencombine_shortest [a1; …; am] [b1; …; bn] is [(a1,b1); …; (am,bm)] if m <= n. Like combine but stops at the shortest list rather than raising.
split [(a1,b1); …; (an,bn)] is ([a1; …; an], [b1; …; bn]). Transform a list of pairs into a pair of lists. A tail-recursive version of List.split.
compare cmp l1 l2 compares the two lists l1 and l2 using the given comparison function cmp.
compare_lengths l1 l2 compare the lengths of the two lists l1 and l2. Equivalent to compare (length l1) (length l2) but more efficient.
val compare_length_with : 'a t -> int -> intcompare_length_with l x compares the length of the list l to an integer x. Equivalent to compare (length l) x but more efficient.
equal p l1 l2 returns true if l1 and l2 are equal.
flat_map f l maps and flattens at the same time (safe). Evaluation order is not guaranteed.
flat_map_i f l maps with index and flattens at the same time (safe). Evaluation order is not guaranteed.
flatten [l1]; [l2]; … concatenates a list of lists. Safe version of List.flatten.
product comb l1 l2 computes the cartesian product of the two lists, with the given combinator comb.
fold_product f init l1 l2 applies the function f with the accumulator init on all the pair of elements of l1 and l2. Fold on the cartesian product.
cartesian_product [[l1]; [l2]; …; [ln]] produces 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 =
@@ -14,5 +14,12 @@
return @@ x * x;;
val square_even : int list -> int list = <fun>
# square_even [1;2;4;3;5;2];;
-- : int list = [4; 16; 4]
val return : 'a -> 'a treturn x is x.
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).
val head_opt : 'a t -> 'a optionhead_opt l returns Some x (the first element of the list l) or None if the list l is empty.
tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.
val last_opt : 'a t -> 'a optionlast_opt l returns Some x (the last element of l) or None if the list l is empty.
val find_pred : ('a -> bool) -> 'a t -> 'a optionfind_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p.
val find_map : ('a -> 'b option) -> 'a t -> 'b optionfind_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.
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b optionfind_mapi f l is like find_map, but also pass the index to the predicate function.
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) optionfind_idx p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None.
remove ~eq ~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).
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
is_sorted ~cmp l returns true iff l is sorted (according to given order).
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ ~eq:(=) [1;2;1] = [1;2;1]. uniq_succ ~eq:(=) [1;1;2] = [1;2].
group_succ ~eq l groups together consecutive elements that are equal according to eq.
Indices
mapi f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri : (int -> 'a -> unit) -> 'a t -> unititeri f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri2 f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
val foldi : ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'bfoldi f init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
foldi2 f init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
val get_at_idx : int -> 'a t -> 'a optionget_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
val nth_opt : 'a t -> int -> 'a optionnth_opt l n returns Some n-th element of l. Safe version of nth.
val get_at_idx_exn : int -> 'a t -> 'aget_at_idx_exn i l gets the i-th element of l, or
set_at_idx i x l replaces the i-th element with x (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_idx i x l inserts x 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_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
add_nodup ~eq x set adds x to set if it was not already present. Linear time.
remove_one ~eq x set removes one occurrence of x from set. Linear time.
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.
subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. 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.
union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
Other Constructors
val range_by : step:int -> int -> int -> int trange_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.
val range : int -> int -> int trange i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.
val range' : int -> int -> int trange' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].
val (--) : int -> int -> int ti -- j is the list of integers from i to j included. Infix alias for range.
val (--^) : int -> int -> int ti --^ j is the list of integers from i to j excluded. Infix alias for range'.
val replicate : int -> 'a -> 'a treplicate n x replicates the given element x n times.
Association Lists
module Assoc : sig ... endval assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'bassoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b optionassoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.
val assq_opt : 'a -> ('a * 'b) t -> 'b optionassq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
val mem_assoc : ?eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> boolmem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
References on Lists
module Ref : sig ... endmodule type MONAD = sig ... endConversions
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genval random_choose : 'a t -> 'a random_genrandom_choose l randomly chooses an element in the list l.
val random_sequence : 'a random_gen t -> 'a t random_genval to_string : ?start:string -> ?stop:string -> ?sep:string ->
-('a -> string) -> 'a t -> stringto_string ?start ?stop ?sep item_to_string l prints l to a string using sep as a separator between elements of l.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.
of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.
val of_seq_rev : 'a Stdlib.Seq.t -> 'a tof_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from to_std_seq_rev since 3.0.
val of_seq : 'a Stdlib.Seq.t -> 'a tof_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.
of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.
Infix Operators
It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endLet operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a list
IO
\ No newline at end of file
+- : int list = [4; 16; 4]
val return : 'a -> 'a treturn x is x.
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).
val head_opt : 'a t -> 'a optionhead_opt l returns Some x (the first element of the list l) or None if the list l is empty.
tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.
val last_opt : 'a t -> 'a optionlast_opt l returns Some x (the last element of l) or None if the list l is empty.
val find_pred : ('a -> bool) -> 'a t -> 'a optionfind_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p.
val find_map : ('a -> 'b option) -> 'a t -> 'b optionfind_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.
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b optionfind_mapi f l is like find_map, but also pass the index to the predicate function.
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) optionfind_idx p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None.
remove ~eq ~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).
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
is_sorted ~cmp l returns true iff l is sorted (according to given order).
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ ~eq:(=) [1;2;1] = [1;2;1]. uniq_succ ~eq:(=) [1;1;2] = [1;2].
group_succ ~eq l groups together consecutive elements that are equal according to eq.
Indices
mapi f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri : (int -> 'a -> unit) -> 'a t -> unititeri f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri2 f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
val foldi : ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'bfoldi f init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
foldi2 f init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
val get_at_idx : int -> 'a t -> 'a optionget_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
val nth_opt : 'a t -> int -> 'a optionnth_opt l n returns Some n-th element of l. Safe version of nth.
val get_at_idx_exn : int -> 'a t -> 'aget_at_idx_exn i l gets the i-th element of l, or
set_at_idx i x l replaces the i-th element with x (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_idx i x l inserts x 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_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
add_nodup ~eq x set adds x to set if it was not already present. Linear time.
remove_one ~eq x set removes one occurrence of x from set. Linear time.
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.
subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. 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.
union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
Other Constructors
val range_by : step:int -> int -> int -> int trange_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.
val range : int -> int -> int trange i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.
val range' : int -> int -> int trange' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].
val replicate : int -> 'a -> 'a treplicate n x replicates the given element x n times.
Association Lists
module Assoc : sig ... endval assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'bassoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b optionassoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.
val assq_opt : 'a -> ('a * 'b) t -> 'b optionassq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
val mem_assoc : ?eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> boolmem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
References on Lists
module Ref : sig ... endmodule type MONAD = sig ... endConversions
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genval random_choose : 'a t -> 'a random_genrandom_choose l randomly chooses an element in the list l.
val random_sequence : 'a random_gen t -> 'a t random_genval to_string : ?start:string -> ?stop:string -> ?sep:string ->
+('a -> string) -> 'a t -> stringto_string ?start ?stop ?sep item_to_string l prints l to a string using sep as a separator between elements of l.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.
of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.
val of_seq_rev : 'a Stdlib.Seq.t -> 'a tof_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from to_std_seq_rev since 3.0.
val of_seq : 'a Stdlib.Seq.t -> 'a tof_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.
of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.
Infix Operators
It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endinclude module type of Infix
val (--) : int -> int -> int ti -- j is the infix alias for range. Bounds included.
val (--^) : int -> int -> int ti --^ j is the infix alias for range'. Second bound j excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
(and&) is combine_shortest. It allows to perform a synchronized product between two lists, stopping gently at the shortest. Usable both with let+ and let*.
# let f xs ys zs =
+ let+ x = xs
+ and& y = ys
+ and& z = zs in
+ x + y + z;;
+val f : int list -> int list -> int list -> int list = <fun>
+# f [1;2] [5;6;7] [10;10];;
+- : int list = [16; 18]
IO
\ No newline at end of file
diff --git a/dev/containers/CCListLabels/Infix/index.html b/dev/containers/CCListLabels/Infix/index.html
index a1f2d7d9..7eae19b8 100644
--- a/dev/containers/CCListLabels/Infix/index.html
+++ b/dev/containers/CCListLabels/Infix/index.html
@@ -1,9 +1,9 @@
-Infix (containers.CCListLabels.Infix) Module CCListLabels.Infix
val (--) : int -> int -> int ti -- j is the infix alias for range. Bounds included.
val (--^) : int -> int -> int ti --^ j is the infix alias for range'. Second bound j excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a list
include CCShimsMkLetList_.S
(and&) is combine_shortest. It allows to perform a synchronized product between two lists, stopping gently at the shortest. Usable both with let+ and let*.
# let f xs ys zs =
+Infix (containers.CCListLabels.Infix) Module CCListLabels.Infix
val (--) : int -> int -> int ti -- j is the infix alias for range. Bounds included.
val (--^) : int -> int -> int ti --^ j is the infix alias for range'. Second bound j excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
(and&) is combine_shortest. It allows to perform a synchronized product between two lists, stopping gently at the shortest. Usable both with let+ and let*.
# let f xs ys zs =
let+ x = xs
and& y = ys
and& z = zs in
x + y + z;;
val f : int list -> int list -> int list -> int list = <fun>
# f [1;2] [5;6;7] [10;10];;
-- : int list = [16; 18]
\ No newline at end of file
+- : int list = [16; 18]
\ No newline at end of file
diff --git a/dev/containers/CCListLabels/index.html b/dev/containers/CCListLabels/index.html
index 531cb256..2b6fd43d 100644
--- a/dev/containers/CCListLabels/index.html
+++ b/dev/containers/CCListLabels/index.html
@@ -1,5 +1,5 @@
-CCListLabels (containers.CCListLabels) Module CCListLabels
Complements to ListLabels
include module type of Stdlib.ListLabels
val empty : 'a tempty is [].
val is_empty : _ t -> boolis_empty l returns true iff l = [].
map ~f [a0; a1; …; an] applies function f in turn to [a0; a1; …; an]. Safe version of List.map.
append l1 l2 returns the list that is the concatenation of l1 and l2. Safe version of List.append.
cons' l x is the same as x :: l. This is convenient for fold functions such as List.fold_left or Array.fold_left.
filter ~f l returns all the elements of the list l that satisfy the predicate f. The order of the elements in the input list l is preserved. Safe version of List.filter.
val fold_right : f:('a -> 'b -> 'b) -> 'a t -> init:'b -> 'bfold_right ~f [a1; …; an] ~init is f a1 (f a2 ( … (f an init) … )). Safe version of List.fold_right.
val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'afold_while ~f ~init l folds 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.
val fold_map_i : f:('acc -> int -> 'a -> 'acc * 'b) -> init:'acc ->
+CCListLabels (containers.CCListLabels) Module CCListLabels
Complements to ListLabels
include module type of Stdlib.ListLabels
val empty : 'a tempty is [].
val is_empty : _ t -> boolis_empty l returns true iff l = [].
map ~f [a0; a1; …; an] applies function f in turn to [a0; a1; …; an]. Safe version of List.map.
append l1 l2 returns the list that is the concatenation of l1 and l2. Safe version of List.append.
cons' l x is the same as x :: l. This is convenient for fold functions such as List.fold_left or Array.fold_left.
filter ~f l returns all the elements of the list l that satisfy the predicate f. The order of the elements in the input list l is preserved. Safe version of List.filter.
val fold_right : f:('a -> 'b -> 'b) -> 'a t -> init:'b -> 'bfold_right ~f [a1; …; an] ~init is f a1 (f a2 ( … (f an init) … )). Safe version of List.fold_right.
val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'afold_while ~f ~init l folds 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.
reduce f (hd::tl) returns Some (fold_left f hd tl). If l is empty, then None is returned.
reduce_exn is the unsafe version of reduce.
val fold_map2 : f:('acc -> 'a -> 'b -> 'acc * 'c) -> init:'acc ->
'a list -> 'b list -> 'acc * 'c listfold_map2 ~f ~init l1 l2 is to fold_map what List.map2 is to List.map.
val return : 'a -> 'a treturn x is x.
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 ~f l = take_while ~f l, drop_while ~f l.
last n l takes the last n elements of l (or less if l doesn't have that many elements).
val head_opt : 'a t -> 'a optionhead_opt l returns Some x (the first element of the list l) or None if the list l is empty.
tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.
val last_opt : 'a t -> 'a optionlast_opt l returns Some x (the last element of l) or None if the list l is empty.
val find_pred : f:('a -> bool) -> 'a t -> 'a optionfind_pred ~f l finds the first element of l that satisfies f, or returns None if no element satisfies f.
val find_pred_exn : f:('a -> bool) -> 'a t -> 'afind_pred_exn ~f l is the unsafe version of find_pred.
val find_map : f:('a -> 'b option) -> 'a t -> 'b optionfind_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.
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b optionfind_mapi ~f l is like find_map, but also pass the index to the predicate function.
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) optionfind_idx ~f x returns Some (i,x) where x is the i-th element of l, and f x holds. Otherwise returns None.
remove ~eq ~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).
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
is_sorted ~cmp l returns true iff l is sorted (according to given order).
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
uniq_succ ~eq 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.
Indices
mapi ~f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri : f:(int -> 'a -> unit) -> 'a t -> unititeri ~f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri2 ~f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
val foldi : f:('b -> int -> 'a -> 'b) -> init:'b -> 'a t -> 'bfoldi ~f ~init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
foldi2 ~f ~init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
val get_at_idx : int -> 'a t -> 'a optionget_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
val nth_opt : 'a t -> int -> 'a optionnth_opt l n returns Some n-th element of l. Safe version of nth.
val get_at_idx_exn : int -> 'a t -> 'aget_at_idx_exn i l gets the i-th element of l, or
set_at_idx i x l replaces the i-th element with x (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_idx i x l inserts x 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_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
add_nodup ~eq x set adds x to set if it was not already present. Linear time.
remove_one ~eq x set removes one occurrence of x from set. Linear time.
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.
subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. 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.
union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
Other Constructors
val range_by : step:int -> int -> int -> int trange_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.
val range : int -> int -> int trange i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.
val range' : int -> int -> int trange' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].
val (--) : int -> int -> int ti -- j is the list of integers from i to j included. Infix alias for range.
val (--^) : int -> int -> int ti --^ j is the list of integers from i to j excluded. Infix alias for range'.
val replicate : int -> 'a -> 'a treplicate n x replicates the given element x n times.
Association Lists
module Assoc : sig ... endval assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'bassoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b optionassoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.
val assq_opt : 'a -> ('a * 'b) t -> 'b optionassq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
val mem_assoc : ?eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> boolmem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
References on Lists
module Ref : sig ... endmodule type MONAD = sig ... endConversions
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genval random_choose : 'a t -> 'a random_genrandom_choose l randomly chooses an element in the list l.
val random_sequence : 'a random_gen t -> 'a t random_genval 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.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.
of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.
val of_seq_rev : 'a Stdlib.Seq.t -> 'a tof_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from of_std_seq_rev since 3.0.
val of_seq : 'a Stdlib.Seq.t -> 'a tof_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.
of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.
Infix Operators
It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endLet operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a list
IO
\ No newline at end of file
+- : int list = [4; 16; 4]val return : 'a -> 'a treturn x is x.
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 ~f l = take_while ~f l, drop_while ~f l.
last n l takes the last n elements of l (or less if l doesn't have that many elements).
val head_opt : 'a t -> 'a optionhead_opt l returns Some x (the first element of the list l) or None if the list l is empty.
tail_opt l returns Some l' (the given list l without its first element) or None if the list l is empty.
val last_opt : 'a t -> 'a optionlast_opt l returns Some x (the last element of l) or None if the list l is empty.
val find_pred : f:('a -> bool) -> 'a t -> 'a optionfind_pred ~f l finds the first element of l that satisfies f, or returns None if no element satisfies f.
val find_pred_exn : f:('a -> bool) -> 'a t -> 'afind_pred_exn ~f l is the unsafe version of find_pred.
val find_map : f:('a -> 'b option) -> 'a t -> 'b optionfind_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.
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b optionfind_mapi ~f l is like find_map, but also pass the index to the predicate function.
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) optionfind_idx ~f x returns Some (i,x) where x is the i-th element of l, and f x holds. Otherwise returns None.
remove ~eq ~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).
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
is_sorted ~cmp l returns true iff l is sorted (according to given order).
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
uniq_succ ~eq 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.
Indices
mapi ~f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri : f:(int -> 'a -> unit) -> 'a t -> unititeri ~f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri2 ~f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
val foldi : f:('b -> int -> 'a -> 'b) -> init:'b -> 'a t -> 'bfoldi ~f ~init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
foldi2 ~f ~init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
val get_at_idx : int -> 'a t -> 'a optionget_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
val nth_opt : 'a t -> int -> 'a optionnth_opt l n returns Some n-th element of l. Safe version of nth.
val get_at_idx_exn : int -> 'a t -> 'aget_at_idx_exn i l gets the i-th element of l, or
set_at_idx i x l replaces the i-th element with x (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_idx i x l inserts x 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_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
add_nodup ~eq x set adds x to set if it was not already present. Linear time.
remove_one ~eq x set removes one occurrence of x from set. Linear time.
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> boolmem ?eq x l is true iff x is equal to an element of l. A comparator function eq can be provided. Linear time.
subset ~eq l1 l2 tests if all elements of the list l1 are contained in the list l2 by applying eq.
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. 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.
union ~eq l1 l2 is the union of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
inter ~eq l1 l2 is the intersection of the lists l1 and l2 w.r.t. the equality predicate eq. Complexity is product of length of inputs.
Other Constructors
val range_by : step:int -> int -> int -> int trange_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.
val range : int -> int -> int trange i j iterates on integers from i to j included. It works both for decreasing and increasing ranges.
val range' : int -> int -> int trange' i j is like range but the second bound j is excluded. For instance range' 0 5 = [0;1;2;3;4].
val replicate : int -> 'a -> 'a treplicate n x replicates the given element x n times.
Association Lists
module Assoc : sig ... endval assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'bassoc ~eq k alist returns the value v associated with key k in alist. Like Assoc.get_exn.
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b optionassoc_opt ~eq k alist returns Some v if the given key k is present into alist, or None if not present. Like Assoc.get.
val assq_opt : 'a -> ('a * 'b) t -> 'b optionassq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
val mem_assoc : ?eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> boolmem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
References on Lists
module Ref : sig ... endmodule type MONAD = sig ... endConversions
val random : 'a random_gen -> 'a t random_genval random_non_empty : 'a random_gen -> 'a t random_genval random_len : int -> 'a random_gen -> 'a t random_genval random_choose : 'a t -> 'a random_genrandom_choose l randomly chooses an element in the list l.
val random_sequence : 'a random_gen t -> 'a t random_genval 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.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq l returns a Seq.t of the elements of the list l. Renamed from to_std_seq since 3.0.
of_iter iter builds a list from a given iter. In the result, elements appear in the same order as they did in the source iter.
val of_seq_rev : 'a Stdlib.Seq.t -> 'a tof_seq_rev seq builds a list from a given Seq.t, in reverse order. Renamed from of_std_seq_rev since 3.0.
val of_seq : 'a Stdlib.Seq.t -> 'a tof_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.
of_gen gen builds a list from a given gen. In the result, elements appear in the same order as they did in the source gen.
Infix Operators
It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.
module Infix : sig ... endinclude module type of Infix
val (--) : int -> int -> int ti -- j is the infix alias for range. Bounds included.
val (--^) : int -> int -> int ti --^ j is the infix alias for range'. Second bound j excluded.
Let operators on OCaml >= 4.08.0, nothing otherwise
(and&) is combine_shortest. It allows to perform a synchronized product between two lists, stopping gently at the shortest. Usable both with let+ and let*.
# let f xs ys zs =
+ let+ x = xs
+ and& y = ys
+ and& z = zs in
+ x + y + z;;
+val f : int list -> int list -> int list -> int list = <fun>
+# f [1;2] [5;6;7] [10;10];;
+- : int list = [16; 18]
IO
\ No newline at end of file
diff --git a/dev/containers/CCOpt/Infix/index.html b/dev/containers/CCOpt/Infix/index.html
index f254fdab..0741f037 100644
--- a/dev/containers/CCOpt/Infix/index.html
+++ b/dev/containers/CCOpt/Infix/index.html
@@ -1,2 +1,2 @@
-Infix (containers.CCOpt.Infix) Module CCOpt.Infix
f <*> o returns Some (f x) if o is Some x and None if o is None.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a option
\ No newline at end of file
+Infix (containers.CCOpt.Infix) Module CCOpt.Infix
f <*> o returns Some (f x) if o is Some x and None if o is None.
\ No newline at end of file
diff --git a/dev/containers/CCOpt/index.html b/dev/containers/CCOpt/index.html
index 081e9fb0..5f53a4ce 100644
--- a/dev/containers/CCOpt/index.html
+++ b/dev/containers/CCOpt/index.html
@@ -1,2 +1,2 @@
-CCOpt (containers.CCOpt) Module CCOpt
Previous Option module
include module type of CCOption
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_or ~default f o is f x if o = Some x, default otherwise.
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
compare comp o1 o2 compares two options o1 and o2, using custom comparators comp for the value. None is always assumed to be less than Some _.
equal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
bind o f is f v if o is Some v, None otherwise. Monadic bind.
map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.
filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.
val exists : ('a -> bool) -> 'a t -> boolexists f o returns true iff there exists an element for which the provided function f evaluates to true.
val for_all : ('a -> bool) -> 'a t -> boolfor_all f o returns true iff the provided function f evaluates to true for all elements.
val get_or : default:'a -> 'a t -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
val get_exn : 'a t -> 'aget_exn o returns x if o is Some x or fails if o is None.
val get_exn_or : string -> 'a t -> 'aget_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.
val get_lazy : (unit -> 'a) -> 'a t -> 'aget_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.
sequence_l [x1; x2; …; xn] returns Some [y1; y2; …; yn] if every xi is Some yi. Otherwise, if the list contains at least one None, the result is None.
wrap ?handler f x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.
wrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
f <*> (Some x) returns Some (f x) and f <*> None returns None.
Alternatives
or_lazy ~else_ o is o if o is Some _, else_ () if o is None.
val return_if : bool -> 'a -> 'a treturn_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.
Infix Operators
module Infix : sig ... endLet operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a option
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_list l returns Some x (x being the head of the list l), or None if l is the empty list.
val to_result : 'e -> 'a t -> ('a, 'e) Stdlib.resultto_result e o returns Ok x if o is Some x, or Error e if o is None.
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) Stdlib.resultto_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
val of_result : ('a, _) Stdlib.result -> 'a tof_result result returns an option from a result.
val random : 'a random_gen -> 'a t random_genchoice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.
choice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.
to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq o is o as a sequence Seq.t. Some x is the singleton sequence containing x and None is the empty sequence. Same as Stdlib.Option.to_seq Renamed from to_std_seq since 3.0.
\ No newline at end of file
+CCOpt (containers.CCOpt) Module CCOpt
Previous Option module
include module type of CCOption
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_or ~default f o is f x if o = Some x, default otherwise.
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
compare comp o1 o2 compares two options o1 and o2, using custom comparators comp for the value. None is always assumed to be less than Some _.
equal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
bind o f is f v if o is Some v, None otherwise. Monadic bind.
map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.
filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.
val exists : ('a -> bool) -> 'a t -> boolexists f o returns true iff there exists an element for which the provided function f evaluates to true.
val for_all : ('a -> bool) -> 'a t -> boolfor_all f o returns true iff the provided function f evaluates to true for all elements.
val get_or : default:'a -> 'a t -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
val get_exn : 'a t -> 'aget_exn o returns x if o is Some x or fails if o is None.
val get_exn_or : string -> 'a t -> 'aget_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.
val get_lazy : (unit -> 'a) -> 'a t -> 'aget_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.
sequence_l [x1; x2; …; xn] returns Some [y1; y2; …; yn] if every xi is Some yi. Otherwise, if the list contains at least one None, the result is None.
wrap ?handler f x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.
wrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
Alternatives
or_lazy ~else_ o is o if o is Some _, else_ () if o is None.
val return_if : bool -> 'a -> 'a treturn_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.
Infix Operators
module Infix : sig ... endinclude module type of Infix
f <*> o returns Some (f x) if o is Some x and None if o is None.
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_list l returns Some x (x being the head of the list l), or None if l is the empty list.
val to_result : 'e -> 'a t -> ('a, 'e) Stdlib.resultto_result e o returns Ok x if o is Some x, or Error e if o is None.
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) Stdlib.resultto_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
val of_result : ('a, _) Stdlib.result -> 'a tof_result result returns an option from a result.
val random : 'a random_gen -> 'a t random_genchoice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.
choice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.
to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq o is o as a sequence Seq.t. Some x is the singleton sequence containing x and None is the empty sequence. Same as Stdlib.Option.to_seq Renamed from to_std_seq since 3.0.
\ No newline at end of file
diff --git a/dev/containers/CCOption/Infix/index.html b/dev/containers/CCOption/Infix/index.html
index ae4980c9..6ee0dd9b 100644
--- a/dev/containers/CCOption/Infix/index.html
+++ b/dev/containers/CCOption/Infix/index.html
@@ -1,2 +1,2 @@
-Infix (containers.CCOption.Infix) Module CCOption.Infix
f <*> o returns Some (f x) if o is Some x and None if o is None.
Let operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a option
\ No newline at end of file
+Infix (containers.CCOption.Infix) Module CCOption.Infix
f <*> o returns Some (f x) if o is Some x and None if o is None.
\ No newline at end of file
diff --git a/dev/containers/CCOption/index.html b/dev/containers/CCOption/index.html
index 216f5292..ef2d37b9 100644
--- a/dev/containers/CCOption/index.html
+++ b/dev/containers/CCOption/index.html
@@ -1,2 +1,2 @@
-CCOption (containers.CCOption) Module CCOption
Basic operations on the option type.
This module replaces `CCOpt`.
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_or ~default f o is f x if o = Some x, default otherwise.
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
compare comp o1 o2 compares two options o1 and o2, using custom comparators comp for the value. None is always assumed to be less than Some _.
equal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
bind o f is f v if o is Some v, None otherwise. Monadic bind.
map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.
filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.
val exists : ('a -> bool) -> 'a t -> boolexists f o returns true iff there exists an element for which the provided function f evaluates to true.
val for_all : ('a -> bool) -> 'a t -> boolfor_all f o returns true iff the provided function f evaluates to true for all elements.
val get_or : default:'a -> 'a t -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
val get_exn : 'a t -> 'aget_exn o returns x if o is Some x or fails if o is None.
val get_exn_or : string -> 'a t -> 'aget_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.
val get_lazy : (unit -> 'a) -> 'a t -> 'aget_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.
sequence_l [x1; x2; …; xn] returns Some [y1; y2; …; yn] if every xi is Some yi. Otherwise, if the list contains at least one None, the result is None.
wrap ?handler f x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.
wrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
f <*> (Some x) returns Some (f x) and f <*> None returns None.
Alternatives
or_lazy ~else_ o is o if o is Some _, else_ () if o is None.
val return_if : bool -> 'a -> 'a treturn_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.
Infix Operators
module Infix : sig ... endLet operators on OCaml >= 4.08.0, nothing otherwise
include CCShimsMkLet_.S with type 'a t_let := 'a option
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_list l returns Some x (x being the head of the list l), or None if l is the empty list.
val to_result : 'e -> 'a t -> ('a, 'e) Stdlib.resultto_result e o returns Ok x if o is Some x, or Error e if o is None.
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) Stdlib.resultto_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
val of_result : ('a, _) Stdlib.result -> 'a tof_result result returns an option from a result.
val random : 'a random_gen -> 'a t random_genchoice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.
choice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.
to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq o is o as a sequence Seq.t. Some x is the singleton sequence containing x and None is the empty sequence. Same as Stdlib.Option.to_seq Renamed from to_std_seq since 3.0.
\ No newline at end of file
+CCOption (containers.CCOption) Module CCOption
Basic operations on the option type.
This module replaces `CCOpt`.
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_or ~default f o is f x if o = Some x, default otherwise.
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'bmap_lazy default_fn f o if f o if o = Some x, default_fn () otherwise.
val is_some : _ t -> boolis_some (Some x) returns true otherwise it returns false.
val is_none : _ t -> boolis_none None returns true otherwise it returns false.
compare comp o1 o2 compares two options o1 and o2, using custom comparators comp for the value. None is always assumed to be less than Some _.
equal p o1 o2 tests for equality between option types o1 and o2, using a custom equality predicate p.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val none : 'a tAlias to None.
bind o f is f v if o is Some v, None otherwise. Monadic bind.
map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val iter : ('a -> unit) -> 'a t -> unititer f o applies f to o. Iterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.
filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.
val exists : ('a -> bool) -> 'a t -> boolexists f o returns true iff there exists an element for which the provided function f evaluates to true.
val for_all : ('a -> bool) -> 'a t -> boolfor_all f o returns true iff the provided function f evaluates to true for all elements.
val get_or : default:'a -> 'a t -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
val value : 'a t -> default:'a -> 'avalue o ~default is similar to the Stdlib's Option.value and to get_or.
val get_exn : 'a t -> 'aget_exn o returns x if o is Some x or fails if o is None.
val get_exn_or : string -> 'a t -> 'aget_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.
val get_lazy : (unit -> 'a) -> 'a t -> 'aget_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.
sequence_l [x1; x2; …; xn] returns Some [y1; y2; …; yn] if every xi is Some yi. Otherwise, if the list contains at least one None, the result is None.
wrap ?handler f x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.
wrap2 ?handler f x y is similar to wrap but for binary functions.
Applicative
Alternatives
or_lazy ~else_ o is o if o is Some _, else_ () if o is None.
val return_if : bool -> 'a -> 'a treturn_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.
Infix Operators
module Infix : sig ... endinclude module type of Infix
f <*> o returns Some (f x) if o is Some x and None if o is None.
Conversion and IO
val to_list : 'a t -> 'a listto_list o returns [x] if o is Some x or the empty list [] if o is None.
val of_list : 'a list -> 'a tof_list l returns Some x (x being the head of the list l), or None if l is the empty list.
val to_result : 'e -> 'a t -> ('a, 'e) Stdlib.resultto_result e o returns Ok x if o is Some x, or Error e if o is None.
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) Stdlib.resultto_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
val of_result : ('a, _) Stdlib.result -> 'a tof_result result returns an option from a result.
val random : 'a random_gen -> 'a t random_genchoice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.
choice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.
to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.
val to_seq : 'a t -> 'a Stdlib.Seq.tto_seq o is o as a sequence Seq.t. Some x is the singleton sequence containing x and None is the empty sequence. Same as Stdlib.Option.to_seq Renamed from to_std_seq since 3.0.
\ No newline at end of file
diff --git a/dev/containers/CCParse/Infix/index.html b/dev/containers/CCParse/Infix/index.html
index 87f0ee32..912dae26 100644
--- a/dev/containers/CCParse/Infix/index.html
+++ b/dev/containers/CCParse/Infix/index.html
@@ -1,2 +1,2 @@
-Infix (containers.CCParse.Infix) Module CCParse.Infix
Alias to map. p >|= f parses an item x using p, and returns f x.
Alias to bind. p >>= f results in a new parser which behaves as p then, in case of success, applies f to the result.
a <* b parses a into x, parses b and ignores its result, and returns x.
a *> b parses a, then parses b into x, and returns x. The result of a is ignored.
a <?> msg behaves like a, but if a fails, a <?> msg fails with msg instead. Useful as the last choice in a series of <|>. For example: a <|> b <|> c <?> "expected one of a, b, c".
Alias to both. a ||| b parses a, then b, then returns the pair of their results.
\ No newline at end of file
+Infix (containers.CCParse.Infix) Module CCParse.Infix
Alias to map. p >|= f parses an item x using p, and returns f x.
Alias to bind. p >>= f results in a new parser which behaves as p then, in case of success, applies f to the result.
a <* b parses a into x, parses b and ignores its result, and returns x.
a *> b parses a, then parses b into x, and returns x. The result of a is ignored.
a <?> msg behaves like a, but if a fails, a <?> msg fails with msg instead. Useful as the last choice in a series of <|>. For example: a <|> b <|> c <?> "expected one of a, b, c".
Alias to both. a ||| b parses a, then b, then returns the pair of their results.
\ No newline at end of file
diff --git a/dev/containers/CCParse/index.html b/dev/containers/CCParse/index.html
index 7c9b2306..e9ebbe66 100644
--- a/dev/containers/CCParse/index.html
+++ b/dev/containers/CCParse/index.html
@@ -26,4 +26,4 @@ let l' = CCParse.parse_string_exn p l_printed;;
assert (l=l');;Some functions are marked "experimental" and are still subject to change.
module Position : sig ... endmodule Error : sig ... endtype +'a or_error = ('a, Error.t) Stdlib.result'a or_error is either Ok x for some result x : 'a, or an error Error.t.
See stringify_result and Error.to_string to print the error message.
exception ParseError of Error.tval return : 'a -> 'a tAlways succeeds, without consuming its input.
bind f p results in a new parser which behaves as p then, in case of success, applies f to the result.
val eoi : unit tExpect the end of input, fails otherwise.
val empty : unit tSucceed with ().
val fail : string -> 'a tfail msg fails with the given message. It can trigger a backtrack.
parsing s p behaves the same as p, with the information that we are parsing s, if p fails. The message s is added to the error, it does not replace it, not does the location change (the error still points to the same location as in p).
set_error_message msg p behaves like p, but if p fails, set_error_message msg p fails with msg instead and at the current position. The internal error message of p is just discarded.
with_pos p behaves like p, but returns the (starting) position along with p's result.
EXPERIMENTAL
val any_char : char tany_char parses any character. It still fails if the end of input was reached.
val any_char_n : int -> string tany_char_n len parses exactly len characters from the input. Fails if the input doesn't contain at least len chars.
val char : char -> char tchar c parses the character c and nothing else.
A slice of the input, as returned by some combinators such as split_1 or split_list or take.
The idea is that one can use some parsers to cut the input into slices, e.g. split into lines, or split a line into fields (think CSV or TSV). Then a variety of parsers can be used on each slice to extract data from it using recurse.
Slices contain enough information to make it possible for recurse slice p to report failures (if p fails) using locations from the original input, not relative to the slice. Therefore, even after splitting the input into lines using, say, each_line, a failure to parse the 500th line will be reported at line 500 and not at line 1.
EXPERIMENTAL
module Slice : sig ... endFunctions on slices.
recurse slice p parses the slice (most likely obtained via another combinator, such as split_1 or split_n), using p.
The slice contains a position which is used to relocate error messages to their position in the whole input, not just relative to the slice.
EXPERIMENTAL
set_current_slice slice replaces the parser's state with slice.
EXPERIMENTAL
val chars_fold : f:('acc -> char -> [ `Continue of 'acc | `Consume_and_stop of 'acc | `Stop of 'acc | `Fail of string ])
-> 'acc -> ('acc * slice) tchars_fold f acc0 folds over characters of the input. Each char c is passed, along with the current accumulator, to f; f can either:
`Stop acc. In this case the final accumulator acc is returned, and c is not consumed.`Consume_and_stop acc.`Fail msg. In this case the parser fails with the given message.`Continue acc. The parser continues to the next char with the new accumulator.This is a generalization of of chars_if that allows one to transform characters on the fly, skip some, handle escape sequences, etc. It can also be useful as a base component for a lexer.
val chars_fold_transduce : f:('acc -> char -> [ `Continue of 'acc | `Yield of 'acc * char | `Consume_and_stop | `Stop | `Fail of string ])
--> 'acc -> ('acc * string) tSame as char_fold but with the following differences:
`Continue _. The string is built from characters returned by `Yield.`Yield (acc, c) adds c to the returned string and continues parsing with acc.take len parses exactly len characters from the input. Fails if the input doesn't contain at least len chars.
take_if f takes characters as long as they satisfy the predicate f.
take1_if f takes characters as long as they satisfy the predicate f. Fails if no character satisfies f.
val char_if : ?descr:string -> (char -> bool) -> char tchar_if f parses a character c if f c = true. Fails if the next char does not satisfy f.
val chars_if : (char -> bool) -> string tchars_if f parses a string of chars that satisfy f. Cannot fail.
val chars1_if : ?descr:string -> (char -> bool) -> string tLike chars_if, but accepts only non-empty strings. chars1_if p fails if the string accepted by chars_if p is empty. chars1_if p is equivalent to take1_if p >|= Slice.to_string.
val endline : char tParse '\n'.
val space : char tTab or space.
val white : char tTab or space or newline.
val skip_chars : (char -> bool) -> unit tSkip 0 or more chars satisfying the predicate.
val skip_space : unit tSkip ' ' and '\t'.
val skip_white : unit tSkip ' ' and '\t' and '\n'.
suspend f is the same as f (), but evaluates f () only when needed.
val string : string -> string tstring s parses exactly the string s, and nothing else.
many p parses p repeatedly, until p fails, and collects the results into a list.
optional p tries to parse p, and return () whether it succeeded or failed. Cannot fail itself. It consumes input if p succeeded (as much as p consumed), but consumes not input if p failed.
try_ p is just like p (it used to play a role in backtracking semantics but no more).
try_opt p tries to parse using p, and return Some x if p succeeded with x (and consumes what p consumed). Otherwise it returns None and consumes nothing. This cannot fail.
many_until ~until p parses as many p as it can until the until parser successfully returns. If p fails before that then many_until ~until p fails as well. Typically until can be a closing ')' or another termination condition, and what is consumed by until is also consumed by many_until ~until p.
EXPERIMENTAL
try_or p1 ~f ~else_:p2 attempts to parse x using p1, and then becomes f x. If p1 fails, then it becomes p2. This can be useful if f is expensive but only ever works if p1 matches (e.g. after an opening parenthesis or some sort of prefix).
try_or_l ?else_ l tries each pair (test, p) in order. If the n-th test succeeds, then try_or_l l behaves like n-th p, whether p fails or not. If they all fail, and else_ is defined, then it behaves like else_. If all fail, and else_ is None, then it fails as well.
This is a performance optimization compared to (<|>). We commit to a branch if the test succeeds, without backtracking at all.
See lookahead_ignore for a convenient way of writing the test conditions.
or_ p1 p2 tries to parse p1, and if it fails, tries p2 from the same position.
both a b parses a, then b, then returns the pair of their results.
many1 p is like many p excepts it fails if the list is empty (i.e. it needs p to succeed at least once).
skip p parses zero or more times p and ignores its result. It is eager, meaning it will continue as long as p succeeds. As soon as p fails, skip p stops consuming any input.
Same as sep but stop when until parses successfully.
lookahead p behaves like p, except it doesn't consume any input.
EXPERIMENTAL
lookahead_ignore p tries to parse input with p, and succeeds if p succeeds. However it doesn't consume any input and returns (), so in effect its only use-case is to detect whether p succeeds, e.g. in try_or_l.
EXPERIMENTAL
val line_str : string tline_str is line >|= Slice.to_string. It parses the next line and turns the slice into a string. The state points to the character immediately after the '\n' character.
split_1 ~on_char looks for on_char in the input, and returns a pair sl1, sl2, where:
sl1 is the slice of the input the precedes the first occurrence of on_char, or the whole input if on_char cannot be found. It does not contain on_char.sl2 is the slice that comes after on_char, or None if on_char couldn't be found. It doesn't contain the first occurrence of on_char (if any).The parser is now positioned at the end of the input.
EXPERIMENTAL
split_list ~on_char splits the input on all occurrences of on_char, returning a list of slices.
EXPERIMENTAL
split_list_at_most ~on_char n applies split_1 ~on_char at most n times, to get a list of n+1 elements. The last element might contain on_char. This is useful to limit the amount of work done by split_list.
EXPERIMENTAL
split_2 ~on_char splits the input into exactly 2 fields, and fails if the split yields less or more than 2 items. EXPERIMENTAL
split_list_map ~on_char p uses split_list ~on_char to split the input, then parses each chunk of the input thus obtained using p.
The difference with sep ~by:(char on_char) p is that sep calls p first, and only tries to find on_char after p returns. While it is more flexible, this technique also means p has to be careful not to consume on_char by error.
A useful specialization of this is each_line, which is basically each_split ~on_char:'\n' p.
EXPERIMENTAL
all returns all the unconsumed input as a slice, and consumes it. Use Slice.to_string to turn it into a string.
Note that lookahead all can be used to peek at the rest of the input without consuming anything.
val all_str : string tall_str accepts all the remaining chars and extracts them into a string. Similar to all but with a string.
EXPERIMENTAL
Memoize the parser. memo p will behave like p, but when called in a state (read: position in input) it has already processed, memo p returns a result directly. The implementation uses an underlying hashtable. This can be costly in memory, but improve the run time a lot if there is a lot of backtracking involving p.
Do not call memo inside other functions, especially with (>>=), map, etc. being so prevalent. Instead the correct way to use it is in a toplevel definition:
let my_expensive_parser = memo (foo *> bar >>= fun i -> …)This function is not thread-safe.
module Infix : sig ... endinclude module type of InfixAlias to map. p >|= f parses an item x using p, and returns f x.
Alias to bind. p >>= f results in a new parser which behaves as p then, in case of success, applies f to the result.
a <* b parses a into x, parses b and ignores its result, and returns x.
a *> b parses a, then parses b into x, and returns x. The result of a is ignored.
a <?> msg behaves like a, but if a fails, a <?> msg fails with msg instead. Useful as the last choice in a series of <|>. For example: a <|> b <|> c <?> "expected one of a, b, c".
Alias to both. a ||| b parses a, then b, then returns the pair of their results.
val stringify_result : 'a or_error -> ('a, string) Stdlib.resultTurn a Error.t-oriented result into a more basic string result.
val parse_string : 'a t -> string -> ('a, string) Stdlib.resultParse a string using the parser.
Version of parse_string that returns a more detailed error.
val parse_string_exn : 'a t -> string -> 'aval parse_file : 'a t -> string -> ('a, string) Stdlib.resultparse_file p filename parses file named filename with p by opening the file and reading it whole.
Version of parse_file that returns a more detailed error.
val parse_file_exn : 'a t -> string -> 'aSame as parse_file, but
module U : sig ... endmodule Debug_ : sig ... endDebugging utils. EXPERIMENTAL
Same as char_fold but with the following differences:
`Continue _. The string is built from characters returned by `Yield.`Yield (acc, c) adds c to the returned string and continues parsing with acc.take len parses exactly len characters from the input. Fails if the input doesn't contain at least len chars.
take_if f takes characters as long as they satisfy the predicate f.
take1_if f takes characters as long as they satisfy the predicate f. Fails if no character satisfies f.
val char_if : ?descr:string -> (char -> bool) -> char tchar_if f parses a character c if f c = true. Fails if the next char does not satisfy f.
val chars_if : (char -> bool) -> string tchars_if f parses a string of chars that satisfy f. Cannot fail.
val chars1_if : ?descr:string -> (char -> bool) -> string tLike chars_if, but accepts only non-empty strings. chars1_if p fails if the string accepted by chars_if p is empty. chars1_if p is equivalent to take1_if p >|= Slice.to_string.
val endline : char tParse '\n'.
val space : char tTab or space.
val white : char tTab or space or newline.
val skip_chars : (char -> bool) -> unit tSkip 0 or more chars satisfying the predicate.
val skip_space : unit tSkip ' ' and '\t'.
val skip_white : unit tSkip ' ' and '\t' and '\n'.
suspend f is the same as f (), but evaluates f () only when needed.
val string : string -> string tstring s parses exactly the string s, and nothing else.
many p parses p repeatedly, until p fails, and collects the results into a list.
optional p tries to parse p, and return () whether it succeeded or failed. Cannot fail itself. It consumes input if p succeeded (as much as p consumed), but consumes not input if p failed.
try_ p is just like p (it used to play a role in backtracking semantics but no more).
try_opt p tries to parse using p, and return Some x if p succeeded with x (and consumes what p consumed). Otherwise it returns None and consumes nothing. This cannot fail.
many_until ~until p parses as many p as it can until the until parser successfully returns. If p fails before that then many_until ~until p fails as well. Typically until can be a closing ')' or another termination condition, and what is consumed by until is also consumed by many_until ~until p.
EXPERIMENTAL
try_or p1 ~f ~else_:p2 attempts to parse x using p1, and then becomes f x. If p1 fails, then it becomes p2. This can be useful if f is expensive but only ever works if p1 matches (e.g. after an opening parenthesis or some sort of prefix).
try_or_l ?else_ l tries each pair (test, p) in order. If the n-th test succeeds, then try_or_l l behaves like n-th p, whether p fails or not. If they all fail, and else_ is defined, then it behaves like else_. If all fail, and else_ is None, then it fails as well.
This is a performance optimization compared to (<|>). We commit to a branch if the test succeeds, without backtracking at all.
See lookahead_ignore for a convenient way of writing the test conditions.
or_ p1 p2 tries to parse p1, and if it fails, tries p2 from the same position.
both a b parses a, then b, then returns the pair of their results.
many1 p is like many p excepts it fails if the list is empty (i.e. it needs p to succeed at least once).
skip p parses zero or more times p and ignores its result. It is eager, meaning it will continue as long as p succeeds. As soon as p fails, skip p stops consuming any input.
Same as sep but stop when until parses successfully.
lookahead p behaves like p, except it doesn't consume any input.
EXPERIMENTAL
lookahead_ignore p tries to parse input with p, and succeeds if p succeeds. However it doesn't consume any input and returns (), so in effect its only use-case is to detect whether p succeeds, e.g. in try_or_l.
EXPERIMENTAL
val line_str : string tline_str is line >|= Slice.to_string. It parses the next line and turns the slice into a string. The state points to the character immediately after the '\n' character.
split_1 ~on_char looks for on_char in the input, and returns a pair sl1, sl2, where:
sl1 is the slice of the input the precedes the first occurrence of on_char, or the whole input if on_char cannot be found. It does not contain on_char.sl2 is the slice that comes after on_char, or None if on_char couldn't be found. It doesn't contain the first occurrence of on_char (if any).The parser is now positioned at the end of the input.
EXPERIMENTAL
split_list ~on_char splits the input on all occurrences of on_char, returning a list of slices.
EXPERIMENTAL
split_list_at_most ~on_char n applies split_1 ~on_char at most n times, to get a list of n+1 elements. The last element might contain on_char. This is useful to limit the amount of work done by split_list.
EXPERIMENTAL
split_2 ~on_char splits the input into exactly 2 fields, and fails if the split yields less or more than 2 items. EXPERIMENTAL
split_list_map ~on_char p uses split_list ~on_char to split the input, then parses each chunk of the input thus obtained using p.
The difference with sep ~by:(char on_char) p is that sep calls p first, and only tries to find on_char after p returns. While it is more flexible, this technique also means p has to be careful not to consume on_char by error.
A useful specialization of this is each_line, which is basically each_split ~on_char:'\n' p.
EXPERIMENTAL
all returns all the unconsumed input as a slice, and consumes it. Use Slice.to_string to turn it into a string.
Note that lookahead all can be used to peek at the rest of the input without consuming anything.
val all_str : string tall_str accepts all the remaining chars and extracts them into a string. Similar to all but with a string.
EXPERIMENTAL
Memoize the parser. memo p will behave like p, but when called in a state (read: position in input) it has already processed, memo p returns a result directly. The implementation uses an underlying hashtable. This can be costly in memory, but improve the run time a lot if there is a lot of backtracking involving p.
Do not call memo inside other functions, especially with (>>=), map, etc. being so prevalent. Instead the correct way to use it is in a toplevel definition:
let my_expensive_parser = memo (foo *> bar >>= fun i -> …)This function is not thread-safe.
module Infix : sig ... endinclude module type of InfixAlias to map. p >|= f parses an item x using p, and returns f x.
Alias to bind. p >>= f results in a new parser which behaves as p then, in case of success, applies f to the result.
a <* b parses a into x, parses b and ignores its result, and returns x.
a *> b parses a, then parses b into x, and returns x. The result of a is ignored.
a <?> msg behaves like a, but if a fails, a <?> msg fails with msg instead. Useful as the last choice in a series of <|>. For example: a <|> b <|> c <?> "expected one of a, b, c".
Alias to both. a ||| b parses a, then b, then returns the pair of their results.
val stringify_result : 'a or_error -> ('a, string) Stdlib.resultTurn a Error.t-oriented result into a more basic string result.
val parse_string : 'a t -> string -> ('a, string) Stdlib.resultParse a string using the parser.
Version of parse_string that returns a more detailed error.
val parse_string_exn : 'a t -> string -> 'aval parse_file : 'a t -> string -> ('a, string) Stdlib.resultparse_file p filename parses file named filename with p by opening the file and reading it whole.
Version of parse_file that returns a more detailed error.
val parse_file_exn : 'a t -> string -> 'aSame as parse_file, but
module U : sig ... endmodule Debug_ : sig ... endDebugging utils. EXPERIMENTAL