diff --git a/dev/containers-data/_doc-dir/CHANGELOG.md b/dev/containers-data/_doc-dir/CHANGELOG.md index 4fcf096a..8302baef 100644 --- a/dev/containers-data/_doc-dir/CHANGELOG.md +++ b/dev/containers-data/_doc-dir/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 3.12 + +- add `containers.pp` sublibrary, with Wadler-style pretty printing combinators +- add `CCArray.{max,argmax,min,argmin}` and their _exn counterparts +- add `CCParse.take_until_success` +- add `Option.flat_map_l` +- add `CCSet.{find_first_map,find_last_map}` +- `CCHash`: native FNV hash for int64/int32 + +- fix bugs in CCParse related to `recurse` and `Slice` +- fix: fix Set.find_last_map on OCaml 4.03 +- fix: make sure `Vector.to_{seq,gen}` captures the length initially + ## 3.11 - official OCaml 5 support diff --git a/dev/containers-thread/_doc-dir/CHANGELOG.md b/dev/containers-thread/_doc-dir/CHANGELOG.md index 4fcf096a..8302baef 100644 --- a/dev/containers-thread/_doc-dir/CHANGELOG.md +++ b/dev/containers-thread/_doc-dir/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 3.12 + +- add `containers.pp` sublibrary, with Wadler-style pretty printing combinators +- add `CCArray.{max,argmax,min,argmin}` and their _exn counterparts +- add `CCParse.take_until_success` +- add `Option.flat_map_l` +- add `CCSet.{find_first_map,find_last_map}` +- `CCHash`: native FNV hash for int64/int32 + +- fix bugs in CCParse related to `recurse` and `Slice` +- fix: fix Set.find_last_map on OCaml 4.03 +- fix: make sure `Vector.to_{seq,gen}` captures the length initially + ## 3.11 - official OCaml 5 support diff --git a/dev/containers/CCArray/index.html b/dev/containers/CCArray/index.html index 5cef704b..f07e5f2f 100644 --- a/dev/containers/CCArray/index.html +++ b/dev/containers/CCArray/index.html @@ -1,5 +1,5 @@ -
CCArrayArray utils
type 'a random_gen = Stdlib.Random.State.t -> 'atype 'a printer = Stdlib.Format.formatter -> 'a -> unitget a n returns the element number n of array a. The first element has number 0. The last element has number length a - 1. You can also write a.(n) instead of get a n.
set a n x modifies array a in place, replacing element number n with x. You can also write a.(n) <- x instead of set a n x.
make n x returns a fresh array of length n, initialized with x. All the elements of this new array are initially physically equal to x (in the sense of the == predicate). Consequently, if x is mutable, it is shared among all elements of the array, and modifying x through one of the array entries will modify all other entries at the same time.
create_float n returns a fresh float array of length n, with uninitialized data.
init n f returns a fresh array of length n, with element number i initialized to the result of f i. In other terms, init n f tabulates the results of f applied to the integers 0 to n-1.
make_matrix dimx dimy e returns a two-dimensional array (an array of arrays) with first dimension dimx and second dimension dimy. All the elements of this new matrix are initially physically equal to e. The element (x,y) of a matrix m is accessed with the notation m.(x).(y).
append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2.
Same as append, but concatenates a list of arrays.
sub a pos len returns a fresh array of length len, containing the elements number pos to pos + len - 1 of array a.
copy a returns a copy of a, that is, a fresh array containing the same elements as a.
fill a pos len x modifies the array a in place, storing x in elements number pos to pos + len - 1.
blit src src_pos dst dst_pos len copies len elements from array src, starting at element number src_pos, to array dst, starting at element number dst_pos. It works correctly even if src and dst are the same array, and the source and destination chunks overlap.
iter f a applies function f in turn to all the elements of a. It is equivalent to f a.(0); f a.(1); ...; f a.(length a - 1); ().
Same as iter, but the function is applied to the index of the element as first argument, and the element itself as second argument.
map f a applies function f to all the elements of a, and builds an array with the results returned by f: [| f a.(0); f a.(1); ...; f a.(length a - 1) |].
Same as map, but the function is applied to the index of the element as first argument, and the element itself as second argument.
fold_left f init a computes f (... (f (f init a.(0)) a.(1)) ...) a.(n-1), where n is the length of the array a.
fold_right f a init computes f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...)), where n is the length of the array a.
iter2 f a b applies function f to all the elements of a and b.
map2 f a b applies function f to all the 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)|].
for_all f [|a1; ...; an|] checks if all elements of the array satisfy the predicate f. That is, it returns (f a1) && (f a2) && ... && (f an).
exists f [|a1; ...; an|] checks if at least one element of the array satisfies the predicate f. That is, it returns (f a1) || (f a2) || ... || (f an).
Same as mem, but uses physical equality instead of structural equality to compare list elements.
find_opt f a returns the first element of the array a that satisfies the predicate f, or None if there is no value that satisfies f in the array a.
split [|(a1,b1); ...; (an,bn)|] is ([|a1; ...; an|], [|b1; ...; bn|]).
combine [|a1; ...; an|] [|b1; ...; bn|] is [|(a1,b1); ...; (an,bn)|]. Raise Invalid_argument if the two arrays have different lengths.
Sort an array in increasing order according to a comparison function. The comparison function must return 0 if its arguments compare as equal, a positive integer if the first is greater, and a negative integer if the first is smaller (see below for a complete specification). For example, Stdlib.compare is a suitable comparison function. After calling sort, the array is sorted in place in increasing order. sort is guaranteed to run in constant heap space and (at most) logarithmic stack space.
The current implementation uses Heap Sort. It runs in constant stack space.
Specification of the comparison function: Let a be the array and cmp the comparison function. The following must be true for all x, y, z in a :
cmp x y > 0 if and only if cmp y x < 0cmp x y >= 0 and cmp y z >= 0 then cmp x z >= 0When sort returns, a contains the same elements as before, reordered in such a way that for all i and j valid indices of a :
cmp a.(i) a.(j) >= 0 if and only if i >= jSame as sort, but the sorting algorithm is stable (i.e. elements that compare equal are kept in their original order) and not guaranteed to run in constant heap space.
The current implementation uses Merge Sort. It uses a temporary array of length n/2, where n is the length of the array. It is usually faster than the current implementation of sort.
Same as sort or stable_sort, whichever is faster on typical input.
val to_seqi : 'a array -> (int * 'a) Stdlib.Seq.tIterate on the array, in increasing order, yielding indices along elements. Modifications of the array during iteration will be reflected in the sequence.
val of_seq : 'a Stdlib.Seq.t -> 'a arrayCreate an array from the generator
val 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 map_inplace : ('a -> 'a) -> 'a t -> unitmap_inplace f a replace all elements of a by its image by f.
val mapi_inplace : (int -> 'a -> 'a) -> 'a t -> unitmapi_inplace f a replace all elements of a by its image by f.
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.
val max : ('a -> 'a -> int) -> 'a t -> 'a optionmax cmp a returns None if a is empty, otherwise, returns Some e where e is a maximum element in a with respect to cmp.
val argmax : ('a -> 'a -> int) -> 'a t -> int optionargmax cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a maximum element in a with respect to cmp.
val min : ('a -> 'a -> int) -> 'a t -> 'a optionmin cmp a returns None if a is empty, otherwise, returns Some e where e is a minimum element in a with respect to cmp.
val argmin : ('a -> 'a -> int) -> 'a t -> int optionargmin cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a minimum element in a with respect to cmp.
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 :
+CCArray (containers.CCArray) Module CCArray
Array utils
type 'a random_gen = Stdlib.Random.State.t -> 'atype 'a printer = Stdlib.Format.formatter -> 'a -> unitArrays
get a n returns the element number n of array a. The first element has number 0. The last element has number length a - 1. You can also write a.(n) instead of get a n.
set a n x modifies array a in place, replacing element number n with x. You can also write a.(n) <- x instead of set a n x.
make n x returns a fresh array of length n, initialized with x. All the elements of this new array are initially physically equal to x (in the sense of the == predicate). Consequently, if x is mutable, it is shared among all elements of the array, and modifying x through one of the array entries will modify all other entries at the same time.
create_float n returns a fresh float array of length n, with uninitialized data.
init n f returns a fresh array of length n, with element number i initialized to the result of f i. In other terms, init n f tabulates the results of f applied to the integers 0 to n-1.
make_matrix dimx dimy e returns a two-dimensional array (an array of arrays) with first dimension dimx and second dimension dimy. All the elements of this new matrix are initially physically equal to e. The element (x,y) of a matrix m is accessed with the notation m.(x).(y).
append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2.
Same as append, but concatenates a list of arrays.
sub a pos len returns a fresh array of length len, containing the elements number pos to pos + len - 1 of array a.
copy a returns a copy of a, that is, a fresh array containing the same elements as a.
fill a pos len x modifies the array a in place, storing x in elements number pos to pos + len - 1.
blit src src_pos dst dst_pos len copies len elements from array src, starting at element number src_pos, to array dst, starting at element number dst_pos. It works correctly even if src and dst are the same array, and the source and destination chunks overlap.
Iterators
iter f a applies function f in turn to all the elements of a. It is equivalent to f a.(0); f a.(1); ...; f a.(length a - 1); ().
Same as iter, but the function is applied to the index of the element as first argument, and the element itself as second argument.
map f a applies function f to all the elements of a, and builds an array with the results returned by f: [| f a.(0); f a.(1); ...; f a.(length a - 1) |].
Same as map, but the function is applied to the index of the element as first argument, and the element itself as second argument.
fold_left f init a computes f (... (f (f init a.(0)) a.(1)) ...) a.(n-1), where n is the length of the array a.
fold_right f a init computes f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...)), where n is the length of the array a.
Iterators on two arrays
iter2 f a b applies function f to all the elements of a and b.
map2 f a b applies function f to all the 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)|].
Array scanning
for_all f [|a1; ...; an|] checks if all elements of the array satisfy the predicate f. That is, it returns (f a1) && (f a2) && ... && (f an).
exists f [|a1; ...; an|] checks if at least one element of the array satisfies the predicate f. That is, it returns (f a1) || (f a2) || ... || (f an).
Same as mem, but uses physical equality instead of structural equality to compare list elements.
find_opt f a returns the first element of the array a that satisfies the predicate f, or None if there is no value that satisfies f in the array a.
Arrays of pairs
split [|(a1,b1); ...; (an,bn)|] is ([|a1; ...; an|], [|b1; ...; bn|]).
combine [|a1; ...; an|] [|b1; ...; bn|] is [|(a1,b1); ...; (an,bn)|]. Raise Invalid_argument if the two arrays have different lengths.
Sorting
Sort an array in increasing order according to a comparison function. The comparison function must return 0 if its arguments compare as equal, a positive integer if the first is greater, and a negative integer if the first is smaller (see below for a complete specification). For example, Stdlib.compare is a suitable comparison function. After calling sort, the array is sorted in place in increasing order. sort is guaranteed to run in constant heap space and (at most) logarithmic stack space.
The current implementation uses Heap Sort. It runs in constant stack space.
Specification of the comparison function: Let a be the array and cmp the comparison function. The following must be true for all x, y, z in a :
cmp x y > 0 if and only if cmp y x < 0- if
cmp x y >= 0 and cmp y z >= 0 then cmp x z >= 0
When sort returns, a contains the same elements as before, reordered in such a way that for all i and j valid indices of a :
cmp a.(i) a.(j) >= 0 if and only if i >= j
Same as sort, but the sorting algorithm is stable (i.e. elements that compare equal are kept in their original order) and not guaranteed to run in constant heap space.
The current implementation uses Merge Sort. It uses a temporary array of length n/2, where n is the length of the array. It is usually faster than the current implementation of sort.
Same as sort or stable_sort, whichever is faster on typical input.
Arrays and Sequences
val to_seqi : 'a array -> (int * 'a) Stdlib.Seq.tIterate on the array, in increasing order, yielding indices along elements. Modifications of the array during iteration will be reflected in the sequence.
val of_seq : 'a Stdlib.Seq.t -> 'a arrayCreate an array from the generator
val 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 map_inplace : ('a -> 'a) -> 'a t -> unitmap_inplace f a replace all elements of a by its image by f.
val mapi_inplace : (int -> 'a -> 'a) -> 'a t -> unitmapi_inplace f a replace all elements of a by its image by f.
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.
val max : ('a -> 'a -> int) -> 'a t -> 'a optionmax cmp a returns None if a is empty, otherwise, returns Some e where e is a maximum element in a with respect to cmp.
val argmax : ('a -> 'a -> int) -> 'a t -> int optionargmax cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a maximum element in a with respect to cmp.
val min : ('a -> 'a -> int) -> 'a t -> 'a optionmin cmp a returns None if a is empty, otherwise, returns Some e where e is a minimum element in a with respect to cmp.
val argmin : ('a -> 'a -> int) -> 'a t -> int optionargmin cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a minimum element in a with respect to cmp.
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 ->
diff --git a/dev/containers/CCArrayLabels/index.html b/dev/containers/CCArrayLabels/index.html
index b38b4f78..2d394fd4 100644
--- a/dev/containers/CCArrayLabels/index.html
+++ b/dev/containers/CCArrayLabels/index.html
@@ -13,7 +13,7 @@
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.
val max : cmp:('a -> 'a -> int) -> 'a t -> 'a optionmax ~cmp a returns None if a is empty, otherwise, returns Some e where e is a maximum element in a with respect to cmp.
val argmax : cmp:('a -> 'a -> int) -> 'a t -> int optionargmax ~cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a maximum element in a with respect to cmp.
val min : cmp:('a -> 'a -> int) -> 'a t -> 'a optionmin ~cmp a returns None if a is empty, otherwise, returns Some e where e is a minimum element in a with respect to cmp.
val argmin : cmp:('a -> 'a -> int) -> 'a t -> int optionargmin ~cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a minimum element in a with respect to cmp.
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).
fold_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.
val max : cmp:('a -> 'a -> int) -> 'a t -> 'a optionmax ~cmp a returns None if a is empty, otherwise, returns Some e where e is a maximum element in a with respect to cmp.
val argmax : cmp:('a -> 'a -> int) -> 'a t -> int optionargmax ~cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a maximum element in a with respect to cmp.
val min : cmp:('a -> 'a -> int) -> 'a t -> 'a optionmin ~cmp a returns None if a is empty, otherwise, returns Some e where e is a minimum element in a with respect to cmp.
val argmin : cmp:('a -> 'a -> int) -> 'a t -> int optionargmin ~cmp a returns None if a is empty, otherwise, returns Some i where i is the index of a minimum element in a with respect to cmp.
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 ->
diff --git a/dev/containers/CCOpt/index.html b/dev/containers/CCOpt/index.html
index 5376ef3e..d7d01ef8 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 is f x 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.
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b listflat_map_l f o is [] if o is None, or f x if o is Some x.
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.
Let operators on OCaml >= 4.08.0, nothing otherwise
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.
to_result e o returns Ok x if o is Some x, or Error e if o is None.
to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
type 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'aval 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.
val choice_seq : 'a t Stdlib.Seq.t -> 'a tchoice_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 is f x 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.
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b listflat_map_l f o is [] if o is None, or f x if o is Some x.
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.
Let operators on OCaml >= 4.08.0, nothing otherwise
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.
to_result e o returns Ok x if o is Some x, or Error e if o is None.
to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
type 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'aval 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.
val choice_seq : 'a t Stdlib.Seq.t -> 'a tchoice_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/index.html b/dev/containers/CCOption/index.html
index 778a6343..be8933cb 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 is f x 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.
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b listflat_map_l f o is [] if o is None, or f x if o is Some x.
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.
Let operators on OCaml >= 4.08.0, nothing otherwise
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.
to_result e o returns Ok x if o is Some x, or Error e if o is None.
to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
type 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'aval 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.
val choice_seq : 'a t Stdlib.Seq.t -> 'a tchoice_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 is f x 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.
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b listflat_map_l f o is [] if o is None, or f x if o is Some x.
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.
Let operators on OCaml >= 4.08.0, nothing otherwise
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.
to_result e o returns Ok x if o is Some x, or Error e if o is None.
to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
type 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'aval 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.
val choice_seq : 'a t Stdlib.Seq.t -> 'a tchoice_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/index.html b/dev/containers/CCParse/index.html
index 89909972..e04503f2 100644
--- a/dev/containers/CCParse/index.html
+++ b/dev/containers/CCParse/index.html
@@ -43,6 +43,6 @@ assert (l=l');;->
'acc ->
- ('acc * string) t
Same as chars_fold but with the following differences:
- returns a string along with the accumulator, rather than the slice of all the characters accepted by
`Continue _. The string is built from characters returned by `Yield. - new case
`Yield (acc, c) adds c to the returned string and continues parsing with acc.
take_until_success p accumulates characters of the input into a slice, until p successfully parses a value x; then it returns slice, x.
NOTE performance wise, if p does a lot of work at each position, this can be costly (thing naive substring search if p is string "very long needle").
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.
A practical use case is to implement recursive parsers manually, as described in fix. The parser is let rec p () = …, and suspend p can be used in the definition to use p.
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 test consumes input, the state is restored before calling p. 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. It can also provide better error messages, because failures in the parser will not be reported as failures in try_or_l.
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
Fixpoint combinator. fix (fun self -> p) is the parser p, in which self refers to the parser p itself (which is useful to parse recursive structures.
An alternative, manual implementation to let p = fix (fun self -> q) is:
let rec p () =
+ ('acc * string) t
Same as chars_fold but with the following differences:
- returns a string along with the accumulator, rather than the slice of all the characters accepted by
`Continue _. The string is built from characters returned by `Yield. - new case
`Yield (acc, c) adds c to the returned string and continues parsing with acc.
take_until_success p accumulates characters of the input into a slice, until p successfully parses a value x; then it returns slice, x.
NOTE performance wise, if p does a lot of work at each position, this can be costly (thing naive substring search if p is string "very long needle").
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.
A practical use case is to implement recursive parsers manually, as described in fix. The parser is let rec p () = …, and suspend p can be used in the definition to use p.
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 test consumes input, the state is restored before calling p. 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. It can also provide better error messages, because failures in the parser will not be reported as failures in try_or_l.
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
Fixpoint combinator. fix (fun self -> p) is the parser p, in which self refers to the parser p itself (which is useful to parse recursive structures.
An alternative, manual implementation to let p = fix (fun self -> q) is:
let rec p () =
let self = suspend p in
q
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.
Infix
module Infix : sig ... endinclude module type of 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.
Alias to or_.
a <|> b tries to parse a, and if a fails without consuming any input, backtracks and tries to parse b, otherwise it fails as a.
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.
Let operators on OCaml >= 4.08.0, nothing otherwise
Parse input
Turn a Error.t-oriented result into a more basic string result.
Version of parse_string that returns a more detailed error.
val parse_string_exn : 'a t -> string -> 'aparse_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
\ No newline at end of file
diff --git a/dev/containers/CCSet/Make/index.html b/dev/containers/CCSet/Make/index.html
index d2c359d9..1dffc30b 100644
--- a/dev/containers/CCSet/Make/index.html
+++ b/dev/containers/CCSet/Make/index.html
@@ -1,6 +1,6 @@
Make (containers.CCSet.Make) Module CCSet.Make
Parameters
module O : Stdlib.Set.OrderedTypeSignature
include Set.S with type t = Set.Make(O).t with type elt = O.t
type elt = O.tThe type of the set elements.
type t = Stdlib.Set.Make(O).tThe type of sets.
val empty : tThe empty set.
val is_empty : t -> boolTest whether a set is empty or not.
add x s returns a set containing all elements of s, plus x. If x was already in s, s is returned unchanged (the result of the function is then physically equal to s).
remove x s returns a set containing all elements of s, except x. If x was not in s, s is returned unchanged (the result of the function is then physically equal to s).
Total ordering between sets. Can be used as the ordering function for doing sets of sets.
equal s1 s2 tests whether the sets s1 and s2 are equal, that is, contain equal elements.
iter f s applies f in turn to all elements of s. The elements of s are presented to f in increasing order with respect to the ordering over the type of the elements.
map f s is the set whose elements are f a0,f a1... f
- aN, where a0,a1...aN are the elements of s.
The elements are passed to f in increasing order with respect to the ordering over the type of the elements.
If no element of s is changed by f, s is returned unchanged. (If each output of f is physically equal to its input, the returned set is physically equal to s.)
fold f s init computes (f xN ... (f x2 (f x1 init))...), where x1 ... xN are the elements of s, in increasing order.
for_all f s checks if all elements of the set satisfy the predicate f.
exists f s checks if at least one element of the set satisfies the predicate f.
filter f s returns the set of all elements in s that satisfy predicate f. If f satisfies every element in s, s is returned unchanged (the result of the function is then physically equal to s).
filter_map f s returns the set of all v such that f x = Some v for some element x of s.
For example,
filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
is the set of halves of the even elements of s.
If no element of s is changed or dropped by f (if f x = Some x for each element x), then s is returned unchanged: the result of the function is then physically equal to s.
partition f s returns a pair of sets (s1, s2), where s1 is the set of all the elements of s that satisfy the predicate f, and s2 is the set of all the elements of s that do not satisfy f.
val cardinal : t -> intReturn the number of elements of a set.
Return the list of all elements of the given set. The returned list is sorted in increasing order with respect to the ordering Ord.compare, where Ord is the argument given to Stdlib.Set.Make.
Return the smallest element of the given set (with respect to the Ord.compare ordering), or raise Not_found if the set is empty.
Return one element of the given set, or raise Not_found if the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.
split x s returns a triple (l, present, r), where l is the set of elements of s that are strictly less than x; r is the set of elements of s that are strictly greater than x; present is false if s contains no element equal to x, or true if s contains an element equal to x.
find x s returns the element of s equal to x (according to Ord.compare), or raise Not_found if no such element exists.
of_list l creates a set from a list of elements. This is usually more efficient than folding add over the list, except perhaps for lists with many duplicated elements.
Iterators
val to_seq_from : elt -> t -> elt Stdlib.Seq.tto_seq_from x s iterates on a subset of the elements of s in ascending order, from x or above.
val to_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in ascending order
val to_rev_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in descending order
Safe version of find_first.
find_first_map f s find the minimum element x of s such that f x = Some y and return Some y. Otherwise returns None.
find_last_map f s find the maximum element x of s such that f x = Some y and return Some y. Otherwise returns None.
val of_seq : elt Stdlib.Seq.t -> tBuild a set from the given seq of elements.
val add_seq : elt Stdlib.Seq.t -> t -> tval to_string :
+ aN, where a0,a1...aN are the elements of s.The elements are passed to f in increasing order with respect to the ordering over the type of the elements.
If no element of s is changed by f, s is returned unchanged. (If each output of f is physically equal to its input, the returned set is physically equal to s.)
fold f s init computes (f xN ... (f x2 (f x1 init))...), where x1 ... xN are the elements of s, in increasing order.
for_all f s checks if all elements of the set satisfy the predicate f.
exists f s checks if at least one element of the set satisfies the predicate f.
filter f s returns the set of all elements in s that satisfy predicate f. If f satisfies every element in s, s is returned unchanged (the result of the function is then physically equal to s).
filter_map f s returns the set of all v such that f x = Some v for some element x of s.
For example,
filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
is the set of halves of the even elements of s.
If no element of s is changed or dropped by f (if f x = Some x for each element x), then s is returned unchanged: the result of the function is then physically equal to s.
partition f s returns a pair of sets (s1, s2), where s1 is the set of all the elements of s that satisfy the predicate f, and s2 is the set of all the elements of s that do not satisfy f.
val cardinal : t -> intReturn the number of elements of a set.
Return the list of all elements of the given set. The returned list is sorted in increasing order with respect to the ordering Ord.compare, where Ord is the argument given to Stdlib.Set.Make.
Return the smallest element of the given set (with respect to the Ord.compare ordering), or raise Not_found if the set is empty.
Return one element of the given set, or raise Not_found if the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.
split x s returns a triple (l, present, r), where l is the set of elements of s that are strictly less than x; r is the set of elements of s that are strictly greater than x; present is false if s contains no element equal to x, or true if s contains an element equal to x.
find x s returns the element of s equal to x (according to Ord.compare), or raise Not_found if no such element exists.
of_list l creates a set from a list of elements. This is usually more efficient than folding add over the list, except perhaps for lists with many duplicated elements.
Iterators
val to_seq_from : elt -> t -> elt Stdlib.Seq.tto_seq_from x s iterates on a subset of the elements of s in ascending order, from x or above.
val to_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in ascending order
val to_rev_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in descending order
Safe version of find_first.
find_first_map f s find the minimum element x of s such that f x = Some y and return Some y. Otherwise returns None.
find_last_map f s find the maximum element x of s such that f x = Some y and return Some y. Otherwise returns None.
val of_seq : elt Stdlib.Seq.t -> tBuild a set from the given seq of elements.
val add_seq : elt Stdlib.Seq.t -> t -> tval to_string :
?start:string ->
?stop:string ->
?sep:string ->
diff --git a/dev/containers/CCSet/module-type-S/index.html b/dev/containers/CCSet/module-type-S/index.html
index d67a4c96..5c8737f4 100644
--- a/dev/containers/CCSet/module-type-S/index.html
+++ b/dev/containers/CCSet/module-type-S/index.html
@@ -1,6 +1,6 @@
S (containers.CCSet.S) Module type CCSet.S
include Stdlib.Set.S
val empty : tThe empty set.
val is_empty : t -> boolTest whether a set is empty or not.
add x s returns a set containing all elements of s, plus x. If x was already in s, s is returned unchanged (the result of the function is then physically equal to s).
remove x s returns a set containing all elements of s, except x. If x was not in s, s is returned unchanged (the result of the function is then physically equal to s).
Total ordering between sets. Can be used as the ordering function for doing sets of sets.
equal s1 s2 tests whether the sets s1 and s2 are equal, that is, contain equal elements.
iter f s applies f in turn to all elements of s. The elements of s are presented to f in increasing order with respect to the ordering over the type of the elements.
map f s is the set whose elements are f a0,f a1... f
- aN, where a0,a1...aN are the elements of s.
The elements are passed to f in increasing order with respect to the ordering over the type of the elements.
If no element of s is changed by f, s is returned unchanged. (If each output of f is physically equal to its input, the returned set is physically equal to s.)
fold f s init computes (f xN ... (f x2 (f x1 init))...), where x1 ... xN are the elements of s, in increasing order.
for_all f s checks if all elements of the set satisfy the predicate f.
exists f s checks if at least one element of the set satisfies the predicate f.
filter f s returns the set of all elements in s that satisfy predicate f. If f satisfies every element in s, s is returned unchanged (the result of the function is then physically equal to s).
filter_map f s returns the set of all v such that f x = Some v for some element x of s.
For example,
filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
is the set of halves of the even elements of s.
If no element of s is changed or dropped by f (if f x = Some x for each element x), then s is returned unchanged: the result of the function is then physically equal to s.
partition f s returns a pair of sets (s1, s2), where s1 is the set of all the elements of s that satisfy the predicate f, and s2 is the set of all the elements of s that do not satisfy f.
val cardinal : t -> intReturn the number of elements of a set.
Return the list of all elements of the given set. The returned list is sorted in increasing order with respect to the ordering Ord.compare, where Ord is the argument given to Stdlib.Set.Make.
Return the smallest element of the given set (with respect to the Ord.compare ordering), or raise Not_found if the set is empty.
Return one element of the given set, or raise Not_found if the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.
split x s returns a triple (l, present, r), where l is the set of elements of s that are strictly less than x; r is the set of elements of s that are strictly greater than x; present is false if s contains no element equal to x, or true if s contains an element equal to x.
find x s returns the element of s equal to x (according to Ord.compare), or raise Not_found if no such element exists.
of_list l creates a set from a list of elements. This is usually more efficient than folding add over the list, except perhaps for lists with many duplicated elements.
Iterators
val to_seq_from : elt -> t -> elt Stdlib.Seq.tto_seq_from x s iterates on a subset of the elements of s in ascending order, from x or above.
val to_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in ascending order
val to_rev_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in descending order
Safe version of find_first.
find_first_map f s find the minimum element x of s such that f x = Some y and return Some y. Otherwise returns None.
find_last_map f s find the maximum element x of s such that f x = Some y and return Some y. Otherwise returns None.
val of_seq : elt Stdlib.Seq.t -> tBuild a set from the given seq of elements.
val add_seq : elt Stdlib.Seq.t -> t -> tval to_string :
+ aN, where a0,a1...aN are the elements of s.The elements are passed to f in increasing order with respect to the ordering over the type of the elements.
If no element of s is changed by f, s is returned unchanged. (If each output of f is physically equal to its input, the returned set is physically equal to s.)
fold f s init computes (f xN ... (f x2 (f x1 init))...), where x1 ... xN are the elements of s, in increasing order.
for_all f s checks if all elements of the set satisfy the predicate f.
exists f s checks if at least one element of the set satisfies the predicate f.
filter f s returns the set of all elements in s that satisfy predicate f. If f satisfies every element in s, s is returned unchanged (the result of the function is then physically equal to s).
filter_map f s returns the set of all v such that f x = Some v for some element x of s.
For example,
filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
is the set of halves of the even elements of s.
If no element of s is changed or dropped by f (if f x = Some x for each element x), then s is returned unchanged: the result of the function is then physically equal to s.
partition f s returns a pair of sets (s1, s2), where s1 is the set of all the elements of s that satisfy the predicate f, and s2 is the set of all the elements of s that do not satisfy f.
val cardinal : t -> intReturn the number of elements of a set.
Return the list of all elements of the given set. The returned list is sorted in increasing order with respect to the ordering Ord.compare, where Ord is the argument given to Stdlib.Set.Make.
Return the smallest element of the given set (with respect to the Ord.compare ordering), or raise Not_found if the set is empty.
Return one element of the given set, or raise Not_found if the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.
split x s returns a triple (l, present, r), where l is the set of elements of s that are strictly less than x; r is the set of elements of s that are strictly greater than x; present is false if s contains no element equal to x, or true if s contains an element equal to x.
find x s returns the element of s equal to x (according to Ord.compare), or raise Not_found if no such element exists.
of_list l creates a set from a list of elements. This is usually more efficient than folding add over the list, except perhaps for lists with many duplicated elements.
Iterators
val to_seq_from : elt -> t -> elt Stdlib.Seq.tto_seq_from x s iterates on a subset of the elements of s in ascending order, from x or above.
val to_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in ascending order
val to_rev_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in descending order
Safe version of find_first.
find_first_map f s find the minimum element x of s such that f x = Some y and return Some y. Otherwise returns None.
find_last_map f s find the maximum element x of s such that f x = Some y and return Some y. Otherwise returns None.
val of_seq : elt Stdlib.Seq.t -> tBuild a set from the given seq of elements.
val add_seq : elt Stdlib.Seq.t -> t -> tval to_string :
?start:string ->
?stop:string ->
?sep:string ->
diff --git a/dev/containers/_doc-dir/CHANGELOG.md b/dev/containers/_doc-dir/CHANGELOG.md
index 4fcf096a..8302baef 100644
--- a/dev/containers/_doc-dir/CHANGELOG.md
+++ b/dev/containers/_doc-dir/CHANGELOG.md
@@ -1,5 +1,18 @@
# Changelog
+## 3.12
+
+- add `containers.pp` sublibrary, with Wadler-style pretty printing combinators
+- add `CCArray.{max,argmax,min,argmin}` and their _exn counterparts
+- add `CCParse.take_until_success`
+- add `Option.flat_map_l`
+- add `CCSet.{find_first_map,find_last_map}`
+- `CCHash`: native FNV hash for int64/int32
+
+- fix bugs in CCParse related to `recurse` and `Slice`
+- fix: fix Set.find_last_map on OCaml 4.03
+- fix: make sure `Vector.to_{seq,gen}` captures the length initially
+
## 3.11
- official OCaml 5 support