mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
Adding comments
This commit is contained in:
parent
829ceeb147
commit
b04e097cf4
11 changed files with 689 additions and 421 deletions
|
|
@ -28,23 +28,39 @@ val swap : 'a t -> int -> int -> unit
|
|||
@since 1.4 *)
|
||||
|
||||
val get : 'a t -> int -> 'a
|
||||
(** [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].
|
||||
|
||||
Raise [Invalid_argument "index out of bounds"]
|
||||
if [n] is outside the range 0 to [(length a - 1)]. *)
|
||||
|
||||
val get_safe : 'a t -> int -> 'a option
|
||||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index
|
||||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index.
|
||||
@since 0.18 *)
|
||||
|
||||
val set : 'a t -> int -> 'a -> unit
|
||||
(** [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].
|
||||
|
||||
Raise [Invalid_argument "index out of bounds"]
|
||||
if [n] is outside the range 0 to [length a - 1]. *)
|
||||
|
||||
val length : _ t -> int
|
||||
(** Return the length (number of elements) of the given array. *)
|
||||
|
||||
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||
(** [fold f x a] computes [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)],
|
||||
where [n] is the length of the array [a]. *)
|
||||
|
||||
val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||
(** Fold left on array, with index *)
|
||||
(** Fold left on array, with index. *)
|
||||
|
||||
val fold_while : ('a -> 'b -> 'a * [`Stop | `Continue]) -> 'a -> 'b t -> 'a
|
||||
(** Fold left on array until a stop condition via [('a, `Stop)] is
|
||||
indicated by the accumulator
|
||||
indicated by the accumulator.
|
||||
@since 0.8 *)
|
||||
|
||||
val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a t -> 'acc * 'b t
|
||||
|
|
@ -54,20 +70,32 @@ val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a t -> 'acc * 'b t
|
|||
|
||||
val scan_left : ('acc -> 'a -> 'acc) -> 'acc -> 'a t -> 'acc t
|
||||
(** [scan_left f acc a] returns the array
|
||||
[ [|acc; f acc x0; f (f acc a.(0)) a.(1); …|] ]
|
||||
[ [|acc; f acc x0; f (f acc a.(0)) a.(1); …|] ].
|
||||
@since 1.2 *)
|
||||
|
||||
|
||||
val iter : ('a -> unit) -> 'a t -> unit
|
||||
(** [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); ()]. *)
|
||||
|
||||
val iteri : (int -> 'a -> unit) -> 'a t -> unit
|
||||
(** Same as {!Array.iter}, but the
|
||||
function is applied with the index of the element as first argument,
|
||||
and the element itself as second argument. *)
|
||||
|
||||
val blit : 'a t -> int -> 'a t -> int -> int -> unit
|
||||
(** [blit from i into j len] copies [len] elements from the first array
|
||||
to the second. See {!Array.blit}. *)
|
||||
(** [blit v1 o1 v2 o2 len] copies [len] elements
|
||||
from array [v1], starting at element number [o1], to array [v2],
|
||||
starting at element number [o2]. It works correctly even if
|
||||
[v1] and [v2] are the same array, and the source and
|
||||
destination chunks overlap.
|
||||
|
||||
Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not
|
||||
designate a valid subarray of [v1], or if [o2] and [len] do not
|
||||
designate a valid subarray of [v2]. *)
|
||||
|
||||
val reverse_in_place : 'a t -> unit
|
||||
(** Reverse the array in place *)
|
||||
(** Reverse the array in place. *)
|
||||
|
||||
val sorted : ('a -> 'a -> int) -> 'a t -> 'a array
|
||||
(** [sorted cmp a] makes a copy of [a] and sorts it with [cmp].
|
||||
|
|
@ -80,7 +108,6 @@ val sort_indices : ('a -> 'a -> int) -> 'a t -> int array
|
|||
|
||||
In other words, [map (fun i -> a.(i)) (sort_indices cmp a) = sorted cmp a].
|
||||
[sort_indices] yields the inverse permutation of {!sort_ranking}.
|
||||
|
||||
@since 1.0 *)
|
||||
|
||||
val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array
|
||||
|
|
@ -92,17 +119,16 @@ val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array
|
|||
[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)]
|
||||
[lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)].
|
||||
@since 1.0 *)
|
||||
|
||||
val find_map : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find_map f a] returns [Some y] if there is an element [x] such
|
||||
that [f x = Some y], else it returns [None]
|
||||
@since 1.3
|
||||
*)
|
||||
that [f x = Some y], else it returns [None].
|
||||
@since 1.3 *)
|
||||
|
||||
val find : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** Alias to {!find_map}
|
||||
(** Alias to {!find_map}.
|
||||
@deprecated since 1.3 *)
|
||||
|
||||
val find_map_i : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
|
|
@ -110,13 +136,13 @@ val find_map_i : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
|||
@since 1.3 *)
|
||||
|
||||
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
(** Alias to {!find_map_i}
|
||||
(** Alias to {!find_map_i}.
|
||||
@since 0.3.4
|
||||
@deprecated since 1.3 *)
|
||||
|
||||
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
|
||||
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
|
||||
and [p x] holds. Otherwise returns [None]
|
||||
and [p x] holds. Otherwise returns [None].
|
||||
@since 0.3.4 *)
|
||||
|
||||
val lookup : cmp:'a ord -> 'a -> 'a t -> int option
|
||||
|
|
@ -124,11 +150,11 @@ val lookup : cmp:'a ord -> 'a -> 'a t -> int option
|
|||
Undefined behavior if the array is not sorted wrt [cmp].
|
||||
Complexity: [O(log (n))] (dichotomic search).
|
||||
@return [None] if the key is not present, or
|
||||
[Some i] ([i] the index of the key) otherwise *)
|
||||
[Some i] ([i] the index of the key) otherwise. *)
|
||||
|
||||
val lookup_exn : cmp:'a ord -> 'a -> 'a t -> int
|
||||
(** Same as {!lookup}, but
|
||||
@raise Not_found if the key is not present *)
|
||||
@raise Not_found if the key is not present. *)
|
||||
|
||||
val bsearch : cmp:('a -> 'a -> int) -> 'a -> 'a t ->
|
||||
[ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]
|
||||
|
|
@ -144,44 +170,52 @@ val bsearch : cmp:('a -> 'a -> int) -> 'a -> 'a t ->
|
|||
- [`All_lower] if all elements of [arr] are lower than [x]
|
||||
- [`All_bigger] if all elements of [arr] are bigger than [x]
|
||||
- [`Just_after i] if [arr.(i) < x < arr.(i+1)]
|
||||
- [`Empty] if the array is empty
|
||||
- [`Empty] if the array is empty.
|
||||
|
||||
@raise Invalid_argument if the array is found to be unsorted w.r.t [cmp]
|
||||
@raise Invalid_argument if the array is found to be unsorted w.r.t [cmp].
|
||||
@since 0.13 *)
|
||||
|
||||
val for_all : ('a -> bool) -> 'a t -> bool
|
||||
(** [for_all p [|a1; ...; an|]] checks if all elements of the array
|
||||
satisfy the predicate [p]. That is, it returns
|
||||
[(p a1) && (p a2) && ... && (p an)]. *)
|
||||
|
||||
val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
|
||||
(** Forall on pairs of arrays.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
allow different types @since 0.20 *)
|
||||
allow different types.
|
||||
@since 0.20 *)
|
||||
|
||||
val exists : ('a -> bool) -> 'a t -> bool
|
||||
(** [exists p [|a1; ...; an|]] checks if at least one element of
|
||||
the array satisfies the predicate [p]. That is, it returns
|
||||
[(p a1) || (p a2) || ... || (p an)]. *)
|
||||
|
||||
val exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
|
||||
(** Exists on pairs of arrays.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
allow different types @since 0.20 *)
|
||||
allow different types.
|
||||
@since 0.20 *)
|
||||
|
||||
val fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc
|
||||
(** Fold on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
|
||||
(** Iterate on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val shuffle : 'a t -> unit
|
||||
(** Shuffle randomly the array, in place *)
|
||||
(** Shuffle randomly the array, in place. *)
|
||||
|
||||
val shuffle_with : Random.State.t -> 'a t -> unit
|
||||
(** Like shuffle but using a specialized random state *)
|
||||
(** Like shuffle but using a specialized random state. *)
|
||||
|
||||
val random_choose : 'a t -> 'a random_gen
|
||||
(** Choose an element randomly.
|
||||
@raise Not_found if the array/slice is empty *)
|
||||
@raise Not_found if the array/slice is empty. *)
|
||||
|
||||
val to_seq : 'a t -> 'a sequence
|
||||
val to_gen : 'a t -> 'a gen
|
||||
|
|
@ -190,20 +224,25 @@ val to_klist : 'a t -> 'a klist
|
|||
(** {2 IO} *)
|
||||
|
||||
val pp: ?sep:string -> 'a printer -> 'a t printer
|
||||
(** Print an array of items with printing function *)
|
||||
(** Print an array of items with printing function. *)
|
||||
|
||||
val pp_i: ?sep:string -> (int -> 'a printer) -> 'a t printer
|
||||
(** Print an array, giving the printing function both index and item *)
|
||||
(** Print an array, giving the printing function both index and item. *)
|
||||
|
||||
val map : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [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) |]]. *)
|
||||
|
||||
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
|
||||
(** Map on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
(** [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)|]].
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val rev : 'a t -> 'a t
|
||||
(** Copy + reverse in place
|
||||
(** Copy + reverse in place.
|
||||
@since 0.20 *)
|
||||
|
||||
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||
|
|
@ -211,30 +250,30 @@ val filter : ('a -> bool) -> 'a t -> 'a t
|
|||
the given predicate will be kept. *)
|
||||
|
||||
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
|
||||
(** Map each element into another value, or discard it *)
|
||||
(** Map each element into another value, or discard it. *)
|
||||
|
||||
val flat_map : ('a -> 'b t) -> 'a t -> 'b array
|
||||
(** Transform each element into an array, then flatten *)
|
||||
(** Transform each element into an array, then flatten. *)
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** Infix version of {!flat_map} *)
|
||||
(** Infix version of {!flat_map}. *)
|
||||
|
||||
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of {!map}
|
||||
(** Infix version of {!map}.
|
||||
@since 0.8 *)
|
||||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of {!map}
|
||||
(** Infix version of {!map}.
|
||||
@since 0.8 *)
|
||||
|
||||
val except_idx : 'a t -> int -> 'a list
|
||||
(** Remove given index, obtaining the list of the other elements *)
|
||||
(** Remove given index, obtaining the list of the other elements. *)
|
||||
|
||||
val (--) : int -> int -> int t
|
||||
(** Range array *)
|
||||
(** Range array. *)
|
||||
|
||||
val (--^) : int -> int -> int t
|
||||
(** Range array, excluding right bound
|
||||
(** Range array, excluding right bound.
|
||||
@since 0.17 *)
|
||||
|
||||
val random : 'a random_gen -> 'a t random_gen
|
||||
|
|
|
|||
|
|
@ -24,35 +24,64 @@ val equal : 'a equal -> 'a t equal
|
|||
val compare : 'a ord -> 'a t ord
|
||||
|
||||
val get : 'a t -> int -> 'a
|
||||
(** [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].
|
||||
|
||||
Raise [Invalid_argument "index out of bounds"]
|
||||
if [n] is outside the range 0 to [(length a - 1)]. *)
|
||||
|
||||
val get_safe : 'a t -> int -> 'a option
|
||||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index
|
||||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index.
|
||||
@since 0.18 *)
|
||||
|
||||
val set : 'a t -> int -> 'a -> unit
|
||||
(** [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].
|
||||
|
||||
Raise [Invalid_argument "index out of bounds"]
|
||||
if [n] is outside the range 0 to [length a - 1]. *)
|
||||
|
||||
val length : _ t -> int
|
||||
(** Return the length (number of elements) of the given array. *)
|
||||
|
||||
val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a
|
||||
(** [fold f x a] computes [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)],
|
||||
where [n] is the length of the array [a]. *)
|
||||
|
||||
val foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'a
|
||||
(** Fold left on array, with index *)
|
||||
(** Fold left on array, with index. *)
|
||||
|
||||
val fold_while : f:('a -> 'b -> 'a * [`Stop | `Continue]) -> init:'a -> 'b t -> 'a
|
||||
(** Fold left on array until a stop condition via [('a, `Stop)] is
|
||||
indicated by the accumulator
|
||||
indicated by the accumulator.
|
||||
@since 0.8 *)
|
||||
|
||||
val iter : f:('a -> unit) -> 'a t -> unit
|
||||
(** [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); ()]. *)
|
||||
|
||||
val iteri : f:(int -> 'a -> unit) -> 'a t -> unit
|
||||
(** Same as {!Array.iter}, but the
|
||||
function is applied with the index of the element as first argument,
|
||||
and the element itself as second argument. *)
|
||||
|
||||
val blit : 'a t -> int -> 'a t -> int -> int -> unit
|
||||
(** [blit from i into j len] copies [len] elements from the first array
|
||||
to the second. See {!Array.blit}. *)
|
||||
(** [blit v1 o1 v2 o2 len] copies [len] elements
|
||||
from array [v1], starting at element number [o1], to array [v2],
|
||||
starting at element number [o2]. It works correctly even if
|
||||
[v1] and [v2] are the same array, and the source and
|
||||
destination chunks overlap.
|
||||
|
||||
Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not
|
||||
designate a valid subarray of [v1], or if [o2] and [len] do not
|
||||
designate a valid subarray of [v2]. *)
|
||||
|
||||
val reverse_in_place : 'a t -> unit
|
||||
(** Reverse the array in place *)
|
||||
(** Reverse the array in place. *)
|
||||
|
||||
val sorted : f:('a -> 'a -> int) -> 'a t -> 'a array
|
||||
(** [sorted cmp a] makes a copy of [a] and sorts it with [cmp].
|
||||
|
|
@ -60,26 +89,28 @@ val sorted : f:('a -> 'a -> int) -> 'a t -> 'a array
|
|||
|
||||
val sort_indices : f:('a -> 'a -> int) -> 'a t -> int array
|
||||
(** [sort_indices cmp a] returns a new array [b], with the same length as [a],
|
||||
such that [b.(i)] is the index of the [i]-th element of [a] in [sort cmp a].
|
||||
In other words, [map (fun i -> a.(i)) (sort_indices a) = sorted cmp a].
|
||||
[a] is not modified.
|
||||
such that [b.(i)] is the index at which the [i]-th element of [sorted cmp a]
|
||||
appears in [a]. [a] is not modified.
|
||||
|
||||
In other words, [map (fun i -> a.(i)) (sort_indices cmp a) = sorted cmp a].
|
||||
[sort_indices] yields the inverse permutation of {!sort_ranking}.
|
||||
@since 1.0 *)
|
||||
|
||||
val sort_ranking : f:('a -> 'a -> int) -> 'a t -> int array
|
||||
(** [sort_ranking cmp a] returns a new array [b], with the same length as [a],
|
||||
such that [b.(i)] is the position in [sorted cmp a] of the [i]-th
|
||||
element of [a].
|
||||
[a] is not modified.
|
||||
such that [b.(i)] is the index at which the [i]-the element of [a] appears
|
||||
in [sorted cmp a]. [a] is not modified.
|
||||
|
||||
In other words, [map (fun i -> (sorted cmp a).(i)) (sort_ranking cmp a) = a].
|
||||
[sort_ranking] yields the inverse permutation of {!sort_indices}.
|
||||
|
||||
Without duplicates, we also have
|
||||
[lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)]
|
||||
In the absence of duplicate elements in [a], we also have
|
||||
[lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)].
|
||||
@since 1.0 *)
|
||||
|
||||
val find : f:('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find f a] returns [Some y] if there is an element [x] such
|
||||
that [f x = Some y], else it returns [None] *)
|
||||
that [f x = Some y], else it returns [None]. *)
|
||||
|
||||
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
(** Like {!find}, but also pass the index to the predicate function.
|
||||
|
|
@ -87,70 +118,80 @@ val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
|
|||
|
||||
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option
|
||||
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
|
||||
and [p x] holds. Otherwise returns [None]
|
||||
and [p x] holds. Otherwise returns [None].
|
||||
@since 0.3.4 *)
|
||||
|
||||
val lookup : cmp:'a ord -> key:'a -> 'a t -> int option
|
||||
(** Lookup the index of some value in a sorted array.
|
||||
Undefined behavior if the array is not sorted wrt [cmp].
|
||||
Complexity: [O(log (n))] (dichotomic search).
|
||||
@return [None] if the key is not present, or
|
||||
[Some i] ([i] the index of the key) otherwise *)
|
||||
[Some i] ([i] the index of the key) otherwise. *)
|
||||
|
||||
val lookup_exn : cmp:'a ord -> key:'a -> 'a t -> int
|
||||
(** Same as {!lookup_exn}, but
|
||||
@raise Not_found if the key is not present *)
|
||||
(** Same as {!lookup}, but
|
||||
@raise Not_found if the key is not present. *)
|
||||
|
||||
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 arr] finds the index of the object [key] in the array [arr],
|
||||
(** [bsearch ?cmp x arr] finds the index of the object [x] in the array [arr],
|
||||
provided [arr] is {b 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
|
||||
Complexity: [O(log n)] where n is the length of the array
|
||||
(dichotomic search).
|
||||
|
||||
@return
|
||||
- [`At i] if [cmp arr.(i) key = 0] (for some i)
|
||||
- [`All_lower] if all elements of [arr] are lower than [key]
|
||||
- [`All_bigger] if all elements of [arr] are bigger than [key]
|
||||
- [`Just_after i] if [arr.(i) < key < arr.(i+1)]
|
||||
- [`Empty] if the array is empty
|
||||
- [`Just_after i] if [arr.(i) < x < arr.(i+1)]
|
||||
- [`Empty] if the array is empty.
|
||||
|
||||
@raise Invalid_argument if the array is found to be unsorted w.r.t [cmp]
|
||||
@raise Invalid_argument if the array is found to be unsorted w.r.t [cmp].
|
||||
@since 0.13 *)
|
||||
|
||||
val for_all : f:('a -> bool) -> 'a t -> bool
|
||||
(** [for_all p [|a1; ...; an|]] checks if all elements of the array
|
||||
satisfy the predicate [p]. That is, it returns
|
||||
[(p a1) && (p a2) && ... && (p an)]. *)
|
||||
|
||||
val for_all2 : f:('a -> 'b -> bool) -> 'a t -> 'b t -> bool
|
||||
(** Forall on pairs of arrays.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
allow different types @since 0.20 *)
|
||||
allow different types.
|
||||
@since 0.20 *)
|
||||
|
||||
val exists : f:('a -> bool) -> 'a t -> bool
|
||||
(** [exists p [|a1; ...; an|]] checks if at least one element of
|
||||
the array satisfies the predicate [p]. That is, it returns
|
||||
[(p a1) || (p a2) || ... || (p an)]. *)
|
||||
|
||||
val exists2 : f:('a -> 'b -> bool) -> 'a t -> 'b t -> bool
|
||||
(** Exists on pairs of arrays.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
allow different types @since 0.20 *)
|
||||
allow different types.
|
||||
@since 0.20 *)
|
||||
|
||||
val fold2 : f:('acc -> 'a -> 'b -> 'acc) -> init:'acc -> 'a t -> 'b t -> 'acc
|
||||
(** Fold on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val iter2 : f:('a -> 'b -> unit) -> 'a t -> 'b t -> unit
|
||||
(** Iterate on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val shuffle : 'a t -> unit
|
||||
(** Shuffle randomly the array, in place *)
|
||||
(** Shuffle randomly the array, in place. *)
|
||||
|
||||
val shuffle_with : Random.State.t -> 'a t -> unit
|
||||
(** Like shuffle but using a specialized random state *)
|
||||
(** Like shuffle but using a specialized random state. *)
|
||||
|
||||
val random_choose : 'a t -> 'a random_gen
|
||||
(** Choose an element randomly.
|
||||
@raise Not_found if the array/slice is empty *)
|
||||
@raise Not_found if the array/slice is empty. *)
|
||||
|
||||
val to_seq : 'a t -> 'a sequence
|
||||
val to_gen : 'a t -> 'a gen
|
||||
|
|
@ -159,20 +200,25 @@ val to_klist : 'a t -> 'a klist
|
|||
(** {2 IO} *)
|
||||
|
||||
val pp: ?sep:string -> 'a printer -> 'a t printer
|
||||
(** Print an array of items with printing function *)
|
||||
(** Print an array of items with printing function. *)
|
||||
|
||||
val pp_i: ?sep:string -> (int -> 'a printer) -> 'a t printer
|
||||
(** Print an array, giving the printing function both index and item *)
|
||||
(** Print an array, giving the printing function both index and item. *)
|
||||
|
||||
val map : f:('a -> 'b) -> 'a t -> 'b t
|
||||
(** [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) |]]. *)
|
||||
|
||||
val map2 : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
|
||||
(** Map on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
(** [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)|]].
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val rev : 'a t -> 'a t
|
||||
(** Copy + reverse in place
|
||||
(** Copy + reverse in place.
|
||||
@since 0.20 *)
|
||||
|
||||
val filter : f:('a -> bool) -> 'a t -> 'a t
|
||||
|
|
@ -180,30 +226,30 @@ val filter : f:('a -> bool) -> 'a t -> 'a t
|
|||
the given predicate will be kept. *)
|
||||
|
||||
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t
|
||||
(** Map each element into another value, or discard it *)
|
||||
(** Map each element into another value, or discard it. *)
|
||||
|
||||
val flat_map : f:('a -> 'b t) -> 'a t -> 'b array
|
||||
(** Transform each element into an array, then flatten *)
|
||||
(** Transform each element into an array, then flatten. *)
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** Infix version of {!flat_map} *)
|
||||
(** Infix version of {!flat_map}. *)
|
||||
|
||||
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of {!map}
|
||||
(** Infix version of {!map}.
|
||||
@since 0.8 *)
|
||||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of {!map}
|
||||
(** Infix version of {!map}.
|
||||
@since 0.8 *)
|
||||
|
||||
val except_idx : 'a t -> int -> 'a list
|
||||
(** Remove given index, obtaining the list of the other elements *)
|
||||
(** Remove given index, obtaining the list of the other elements. *)
|
||||
|
||||
val (--) : int -> int -> int t
|
||||
(** Range array *)
|
||||
(** Range array. *)
|
||||
|
||||
val (--^) : int -> int -> int t
|
||||
(** Range array, excluding right bound
|
||||
(** Range array, excluding right bound.
|
||||
@since 0.17 *)
|
||||
|
||||
val random : 'a random_gen -> 'a t random_gen
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ type 'a random_gen = Random.State.t -> 'a
|
|||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
type 'a t
|
||||
(** Array slice, containing elements of type ['a] *)
|
||||
(** Array slice, containing elements of type ['a]. *)
|
||||
|
||||
val empty : 'a t
|
||||
|
||||
|
|
@ -21,64 +21,93 @@ val equal : 'a equal -> 'a t equal
|
|||
val compare : 'a ord -> 'a t ord
|
||||
|
||||
val get : 'a t -> int -> 'a
|
||||
(** [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].
|
||||
|
||||
Raise [Invalid_argument "index out of bounds"]
|
||||
if [n] is outside the range 0 to [(length a - 1)]. *)
|
||||
|
||||
val get_safe : 'a t -> int -> 'a option
|
||||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index
|
||||
(** [get_safe a i] returns [Some a.(i)] if [i] is a valid index.
|
||||
@since 0.18 *)
|
||||
|
||||
val make : 'a array -> int -> len:int -> 'a t
|
||||
(** Create a slice from given offset and length..
|
||||
@raise Invalid_argument if the slice isn't valid *)
|
||||
(** Create a slice from given offset and length.
|
||||
@raise Invalid_argument if the slice isn't valid. *)
|
||||
|
||||
val of_slice : ('a array * int * int) -> 'a t
|
||||
(** Make a sub-array from a triple [(arr, i, len)] where [arr] is the array,
|
||||
[i] the offset in [arr], and [len] the number of elements of the slice.
|
||||
@raise Invalid_argument if the slice isn't valid (See {!make}) *)
|
||||
@raise Invalid_argument if the slice isn't valid (See {!make}). *)
|
||||
|
||||
val to_slice : 'a t -> ('a array * int * int)
|
||||
(** Convert into a triple [(arr, i, len)] where [len] is the length of
|
||||
the subarray of [arr] starting at offset [i] *)
|
||||
the sub-array of [arr] starting at offset [i]. *)
|
||||
|
||||
val to_list : 'a t -> 'a list
|
||||
(** Convert directly to a list
|
||||
(** Convert directly to a list.
|
||||
@since 1.0 *)
|
||||
|
||||
val full : 'a array -> 'a t
|
||||
(** Slice that covers the full array *)
|
||||
(** Slice that covers the full array. *)
|
||||
|
||||
val underlying : 'a t -> 'a array
|
||||
(** Underlying array (shared). Modifying this array will modify the slice *)
|
||||
(** Underlying array (shared). Modifying this array will modify the slice. *)
|
||||
|
||||
val copy : 'a t -> 'a array
|
||||
(** Copy into a new array *)
|
||||
(** Copy into a new array. *)
|
||||
|
||||
val sub : 'a t -> int -> int -> 'a t
|
||||
(** Sub-slice *)
|
||||
(** Sub-slice. *)
|
||||
|
||||
val set : 'a t -> int -> 'a -> unit
|
||||
(** [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].
|
||||
|
||||
Raise [Invalid_argument "index out of bounds"]
|
||||
if [n] is outside the range 0 to [length a - 1]. *)
|
||||
|
||||
val length : _ t -> int
|
||||
(** Return the length (number of elements) of the given array. *)
|
||||
|
||||
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||
(** [fold f x a] computes [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)],
|
||||
where [n] is the length of the array [a]. *)
|
||||
|
||||
val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||
(** Fold left on array, with index *)
|
||||
(** Fold left on array, with index. *)
|
||||
|
||||
val fold_while : ('a -> 'b -> 'a * [`Stop | `Continue]) -> 'a -> 'b t -> 'a
|
||||
(** Fold left on array until a stop condition via [('a, `Stop)] is
|
||||
indicated by the accumulator
|
||||
indicated by the accumulator.
|
||||
@since 0.8 *)
|
||||
|
||||
val iter : ('a -> unit) -> 'a t -> unit
|
||||
(** [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); ()]. *)
|
||||
|
||||
val iteri : (int -> 'a -> unit) -> 'a t -> unit
|
||||
(** Same as {!Array.iter}, but the
|
||||
function is applied with the index of the element as first argument,
|
||||
and the element itself as second argument. *)
|
||||
|
||||
val blit : 'a t -> int -> 'a t -> int -> int -> unit
|
||||
(** [blit from i into j len] copies [len] elements from the first array
|
||||
to the second. See {!Array.blit}. *)
|
||||
(** [blit v1 o1 v2 o2 len] copies [len] elements
|
||||
from array [v1], starting at element number [o1], to array [v2],
|
||||
starting at element number [o2]. It works correctly even if
|
||||
[v1] and [v2] are the same array, and the source and
|
||||
destination chunks overlap.
|
||||
|
||||
Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not
|
||||
designate a valid subarray of [v1], or if [o2] and [len] do not
|
||||
designate a valid subarray of [v2]. *)
|
||||
|
||||
val reverse_in_place : 'a t -> unit
|
||||
(** Reverse the array in place *)
|
||||
(** Reverse the array in place. *)
|
||||
|
||||
val sorted : ('a -> 'a -> int) -> 'a t -> 'a array
|
||||
(** [sorted cmp a] makes a copy of [a] and sorts it with [cmp].
|
||||
|
|
@ -91,7 +120,6 @@ val sort_indices : ('a -> 'a -> int) -> 'a t -> int array
|
|||
|
||||
In other words, [map (fun i -> a.(i)) (sort_indices cmp a) = sorted cmp a].
|
||||
[sort_indices] yields the inverse permutation of {!sort_ranking}.
|
||||
|
||||
@since 1.0 *)
|
||||
|
||||
val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array
|
||||
|
|
@ -103,12 +131,12 @@ val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array
|
|||
[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)]
|
||||
[lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)].
|
||||
@since 1.0 *)
|
||||
|
||||
val find : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find f a] returns [Some y] if there is an element [x] such
|
||||
that [f x = Some y], else it returns [None] *)
|
||||
that [f x = Some y], else it returns [None]. *)
|
||||
|
||||
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
(** Like {!find}, but also pass the index to the predicate function.
|
||||
|
|
@ -116,17 +144,17 @@ val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
|||
|
||||
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
|
||||
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
|
||||
and [p x] holds. Otherwise returns [None]
|
||||
and [p x] holds. Otherwise returns [None].
|
||||
@since 0.3.4 *)
|
||||
|
||||
val lookup : cmp:'a ord -> 'a -> 'a t -> int option
|
||||
(** Lookup the index of some value in a sorted array.
|
||||
@return [None] if the key is not present, or
|
||||
[Some i] ([i] the index of the key) otherwise *)
|
||||
[Some i] ([i] the index of the key) otherwise. *)
|
||||
|
||||
val lookup_exn : cmp:'a ord -> 'a -> 'a t -> int
|
||||
(** Same as {!lookup}, but
|
||||
@raise Not_found if the key is not present *)
|
||||
@raise Not_found if the key is not present. *)
|
||||
|
||||
val bsearch : cmp:('a -> 'a -> int) -> 'a -> 'a t ->
|
||||
[ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]
|
||||
|
|
@ -148,38 +176,46 @@ val bsearch : cmp:('a -> 'a -> int) -> 'a -> 'a t ->
|
|||
@since 0.13 *)
|
||||
|
||||
val for_all : ('a -> bool) -> 'a t -> bool
|
||||
(** [for_all p [|a1; ...; an|]] checks if all elements of the array
|
||||
satisfy the predicate [p]. That is, it returns
|
||||
[(p a1) && (p a2) && ... && (p an)]. *)
|
||||
|
||||
val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
|
||||
(** Forall on pairs of arrays.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
allow different types @since 0.20 *)
|
||||
allow different types.
|
||||
@since 0.20 *)
|
||||
|
||||
val exists : ('a -> bool) -> 'a t -> bool
|
||||
(** [exists p [|a1; ...; an|]] checks if at least one element of
|
||||
the array satisfies the predicate [p]. That is, it returns
|
||||
[(p a1) || (p a2) || ... || (p an)]. *)
|
||||
|
||||
val exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
|
||||
(** Exists on pairs of arrays.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
allow different types @since 0.20 *)
|
||||
allow different types.
|
||||
@since 0.20 *)
|
||||
|
||||
val fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc
|
||||
(** Fold on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
|
||||
(** Iterate on two arrays stepwise.
|
||||
@raise Invalid_argument if they have distinct lengths
|
||||
@raise Invalid_argument if they have distinct lengths.
|
||||
@since 0.20 *)
|
||||
|
||||
val shuffle : 'a t -> unit
|
||||
(** Shuffle randomly the array, in place *)
|
||||
(** Shuffle randomly the array, in place. *)
|
||||
|
||||
val shuffle_with : Random.State.t -> 'a t -> unit
|
||||
(** Like shuffle but using a specialized random state *)
|
||||
(** Like shuffle but using a specialized random state. *)
|
||||
|
||||
val random_choose : 'a t -> 'a random_gen
|
||||
(** Choose an element randomly.
|
||||
@raise Not_found if the array/slice is empty *)
|
||||
@raise Not_found if the array/slice is empty. *)
|
||||
|
||||
val to_seq : 'a t -> 'a sequence
|
||||
val to_gen : 'a t -> 'a gen
|
||||
|
|
@ -188,7 +224,7 @@ val to_klist : 'a t -> 'a klist
|
|||
(** {2 IO} *)
|
||||
|
||||
val pp: ?sep:string -> 'a printer -> 'a t printer
|
||||
(** Print an array of items with printing function *)
|
||||
(** Print an array of items with printing function. *)
|
||||
|
||||
val pp_i: ?sep:string -> (int -> 'a printer) -> 'a t printer
|
||||
(** Print an array, giving the printing function both index and item *)
|
||||
(** Print an array, giving the printing function both index and item. *)
|
||||
|
|
|
|||
|
|
@ -7,27 +7,37 @@
|
|||
include module type of Char
|
||||
|
||||
val equal : t -> t -> bool
|
||||
(** The equal function for chars. *)
|
||||
|
||||
val compare : t -> t -> int
|
||||
(** The comparison function for characters, with the same specification as
|
||||
{!Pervasives.compare}. Along with the type [t], this function [compare]
|
||||
allows the module [Char] to be passed as argument to the functors
|
||||
{!Set.Make} and {!Map.Make}. *)
|
||||
|
||||
val lowercase_ascii : t -> t
|
||||
(** See {!Char}
|
||||
(** Convert the given character to its equivalent lowercase character,
|
||||
using the US-ASCII character set.
|
||||
@since 0.20 *)
|
||||
|
||||
val uppercase_ascii : t -> t
|
||||
(** See {!Char}
|
||||
(** Convert the given character to its equivalent uppercase character,
|
||||
using the US-ASCII character set.
|
||||
@since 0.20 *)
|
||||
|
||||
val of_int_exn : int -> t
|
||||
(** Alias to {!Char.chr}
|
||||
@raise Invalid_argument if the int is not within [0,...,255]
|
||||
(** Alias to {!Char.chr}.
|
||||
Return the character with the given ASCII code.
|
||||
@raise Invalid_argument if the int is not within [0,...,255].
|
||||
@since 1.0 *)
|
||||
|
||||
val of_int : int -> t option
|
||||
(** Safe version of {!of_int}
|
||||
(** Safe version of {!of_int_exn}.
|
||||
@since 1.0 *)
|
||||
|
||||
val to_int : t -> int
|
||||
(** Alias to {!Char.code}
|
||||
(** Alias to {!Char.code}.
|
||||
Return the ASCII code of the argument.
|
||||
@since 1.0 *)
|
||||
|
||||
val pp : Buffer.t -> t -> unit
|
||||
|
|
|
|||
|
|
@ -9,79 +9,159 @@
|
|||
type t = int64
|
||||
|
||||
val (+) : t -> t -> t
|
||||
(** Addition. *)
|
||||
|
||||
val (-) : t -> t -> t
|
||||
(** Subtraction. *)
|
||||
|
||||
val (~-) : t -> t
|
||||
(** Unary negation. *)
|
||||
|
||||
val ( * ) : t -> t -> t
|
||||
(** Multiplication. *)
|
||||
|
||||
val (/) : t -> t -> t
|
||||
(** Integer division. Raise [Division_by_zero] if the second
|
||||
argument is zero. This division rounds the real quotient of
|
||||
its arguments towards zero, as specified for {!Pervasives.(/)}. *)
|
||||
|
||||
val (mod) : t -> t -> t
|
||||
(** Integer remainder.
|
||||
If [y = 0], [x mod y] raises [Division_by_zero]. *)
|
||||
|
||||
val abs : t -> t
|
||||
(** Return the absolute value of its argument. *)
|
||||
|
||||
val max_int : t
|
||||
(** The greatest representable 64-bit integer, 2{^63} - 1. *)
|
||||
|
||||
val min_int : t
|
||||
(** The smallest representable 64-bit integer, -2{^63}. *)
|
||||
|
||||
val (land) : t -> t -> t
|
||||
(** Bitwise logical and. *)
|
||||
|
||||
val (lor) : t -> t -> t
|
||||
(** Bitwise logical or. *)
|
||||
|
||||
val (lxor) : t -> t -> t
|
||||
(** Bitwise logical exclusive or. *)
|
||||
|
||||
val lnot : t -> t
|
||||
(** Bitwise logical negation. *)
|
||||
|
||||
val (lsl) : t -> int -> t
|
||||
(** [ x lsl y] shifts [x] to the left by [y] bits.
|
||||
The result is unspecified if [y < 0] or [y >= 64]. *)
|
||||
|
||||
val (lsr) : t -> int -> t
|
||||
(** [x lsr y] shifts [x] to the right by [y] bits.
|
||||
This is a logical shift: zeroes are inserted in the vacated bits
|
||||
regardless of the sign of [x].
|
||||
The result is unspecified if [y < 0] or [y >= 64]. *)
|
||||
|
||||
val (asr) : t -> int -> t
|
||||
(** [x asr y] shifts [x] to the right by [y] bits.
|
||||
This is an arithmetic shift: the sign bit of [x] is replicated
|
||||
and inserted in the vacated bits.
|
||||
The result is unspecified if [y < 0] or [y >= 64]. *)
|
||||
|
||||
val equal : t -> t -> bool
|
||||
(** The equal function for int64s.
|
||||
Same as {!Pervasives.(=) x y)}. *)
|
||||
|
||||
val compare : t -> t -> int
|
||||
(** The comparison function for 64-bit integers, with the same specification as
|
||||
{!Pervasives.compare}. Along with the type [t], this function [compare]
|
||||
allows the module [CCInt64] to be passed as argument to the functors
|
||||
{!Set.Make} and {!Map.Make}. *)
|
||||
|
||||
val hash : t -> int
|
||||
(** Same as {!Pervasives.abs (to_int x)}. *)
|
||||
|
||||
(** {2 Conversion} *)
|
||||
|
||||
val to_int : t -> int
|
||||
(** Convert the given 64-bit integer (type [int64]) to an
|
||||
integer (type [int]). On 64-bit platforms, the 64-bit integer
|
||||
is taken modulo 2{^63}, i.e. the high-order bit is lost
|
||||
during the conversion. On 32-bit platforms, the 64-bit integer
|
||||
is taken modulo 2{^31}, i.e. the top 33 bits are lost
|
||||
during the conversion. *)
|
||||
|
||||
val of_int : int -> t option
|
||||
(** Safe version of {!of_int_exn}. *)
|
||||
|
||||
val of_int_exn : int -> t
|
||||
(** Alias to {!Int64.of_int}
|
||||
@raise Failure in case of failure *)
|
||||
(** Alias to {!Int64.of_int}.
|
||||
Convert the given integer (type [int]) to a 64-bit integer
|
||||
(type [int64]).
|
||||
@raise Failure in case of failure. *)
|
||||
|
||||
val to_int32 : t -> int32
|
||||
(** Convert the given 64-bit integer (type [int64]) to a
|
||||
32-bit integer (type [int32]). The 64-bit integer
|
||||
is taken modulo 2{^32}, i.e. the top 32 bits are lost
|
||||
during the conversion. *)
|
||||
|
||||
val of_int32 : int32 -> t option
|
||||
(** Safe version of {!of_int32_exn}. *)
|
||||
|
||||
val of_int32_exn : int32 -> t
|
||||
(** Alias to {!Int64.of_int32}
|
||||
@raise Failure in case of failure *)
|
||||
Convert the given 32-bit integer (type [int32])
|
||||
to a 64-bit integer (type [int64]).
|
||||
@raise Failure in case of failure. *)
|
||||
|
||||
val to_nativeint : t -> nativeint
|
||||
(** Convert the given 64-bit integer (type [int64]) to a
|
||||
native integer. On 32-bit platforms, the 64-bit integer
|
||||
is taken modulo 2{^32}. On 64-bit platforms,
|
||||
the conversion is exact. *)
|
||||
|
||||
val of_nativeint : nativeint -> t option
|
||||
(** Safe version of {!of_nativeint_exn}. *)
|
||||
|
||||
val of_nativeint_exn : nativeint -> t
|
||||
(** Alias to {!Int64.of_nativeint}
|
||||
@raise Failure in case of failure *)
|
||||
(** Alias to {!Int64.of_nativeint}.
|
||||
Convert the given native integer (type [nativeint])
|
||||
to a 64-bit integer (type [int64]).
|
||||
@raise Failure in case of failure. *)
|
||||
|
||||
val to_float : t -> float
|
||||
(** Convert the given 64-bit integer to a floating-point number. *)
|
||||
|
||||
val of_float : float -> t option
|
||||
(** Safe version of {!of_float_exn}. *)
|
||||
|
||||
val of_float_exn : float -> t
|
||||
(** Alias to {!Int64.of_float}
|
||||
@raise Failure in case of failure *)
|
||||
(** Alias to {!Int64.of_float}.
|
||||
Convert the given floating-point number to a 64-bit integer,
|
||||
discarding the fractional part (truncate towards 0).
|
||||
The result of the conversion is undefined if, after truncation,
|
||||
the number is outside the range \[{!CCInt64.min_int}, {!CCInt64.max_int}\].
|
||||
@raise Failure in case of failure. *)
|
||||
|
||||
val to_string : t -> string
|
||||
(** Return the string representation of its argument, in decimal. *)
|
||||
|
||||
val of_string : string -> t option
|
||||
(** Safe version of {!of_string_exn}. *)
|
||||
|
||||
val of_string_exn : string -> t
|
||||
(** Alias to {!Int64.of_string}.
|
||||
Convert the given string to a 64-bit integer.
|
||||
The string is read in decimal (by default, or if the string
|
||||
begins with [0u]) or in hexadecimal, octal or binary if the
|
||||
string begins with [0x], [0o] or [0b] respectively.
|
||||
|
||||
The [0u] prefix reads the input as an unsigned integer in the range
|
||||
[[0, 2*CCInt64.max_int+1]]. If the input exceeds {!CCInt64.max_int}
|
||||
it is converted to the signed integer
|
||||
[CCInt64.min_int + input - CCInt64.max_int - 1].
|
||||
|
||||
The [_] (underscore) character can appear anywhere in the string
|
||||
and is ignored.
|
||||
Raise [Failure "Int64.of_string"] if the given string is not
|
||||
a valid representation of an integer, or if the integer represented
|
||||
exceeds the range of integers representable in type [int64]. *)
|
||||
|
|
|
|||
|
|
@ -16,39 +16,47 @@ type 'a t = 'a list
|
|||
val empty : 'a t
|
||||
|
||||
val is_empty : _ t -> bool
|
||||
(** [is_empty l] returns [true] iff [l = []]
|
||||
(** [is_empty l] returns [true] iff [l = []].
|
||||
@since 0.11 *)
|
||||
|
||||
val map : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** Safe version of map *)
|
||||
(** Safe version of {!List.map}. *)
|
||||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of [map] with reversed arguments
|
||||
(** Infix version of [map] with reversed arguments.
|
||||
@since 0.5 *)
|
||||
|
||||
val cons : 'a -> 'a t -> 'a t
|
||||
(** [cons x l] is [x::l]
|
||||
(** [cons x l] is [x::l].
|
||||
@since 0.12 *)
|
||||
|
||||
val append : 'a t -> 'a t -> 'a t
|
||||
(** Safe version of append *)
|
||||
(** Safe version of {!List.append}.
|
||||
Concatenate two lists. *)
|
||||
|
||||
val cons_maybe : 'a option -> 'a t -> 'a t
|
||||
(** [cons_maybe (Some x) l] is [x :: l]
|
||||
[cons_maybe None l] is [l]
|
||||
(** [cons_maybe (Some x) l] is [x :: l].
|
||||
[cons_maybe None l] is [l].
|
||||
@since 0.13 *)
|
||||
|
||||
val (@) : 'a t -> 'a t -> 'a t
|
||||
(** Same as [append].
|
||||
Concatenate two lists. *)
|
||||
|
||||
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||
(** Safe version of {!List.filter} *)
|
||||
(** Safe version of {!List.filter}.
|
||||
[filter p l] returns all the elements of the list [l]
|
||||
that satisfy the predicate [p]. The order of the elements
|
||||
in the input list is preserved. *)
|
||||
|
||||
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
|
||||
(** Safe version of [fold_right] *)
|
||||
(** Safe version of [fold_right].
|
||||
[fold_right f [a1; ...; an] b] is
|
||||
[f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. *)
|
||||
|
||||
val fold_while : ('a -> 'b -> 'a * [`Stop | `Continue]) -> 'a -> 'b t -> 'a
|
||||
(** Fold until a stop condition via [('a, `Stop)] is
|
||||
indicated by the accumulator
|
||||
indicated by the accumulator.
|
||||
@since 0.8 *)
|
||||
|
||||
val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a list -> 'acc * 'b list
|
||||
|
|
@ -57,35 +65,39 @@ val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a list -> 'acc * 'b list
|
|||
@since 0.14 *)
|
||||
|
||||
val scan_left : ('acc -> 'a -> 'acc) -> 'acc -> 'a list -> 'acc list
|
||||
(** [scan_left f acc l] returns the list [[acc; f acc x0; f (f acc x0) x1; …]]
|
||||
where [x0], [x1], etc. are the elements of [l]
|
||||
(** [scan_left f acc l] returns the list [[acc; f acc x0; f (f acc x0) x1; ...]]
|
||||
where [x0], [x1], etc. are the elements of [l].
|
||||
@since 1.2 *)
|
||||
|
||||
val fold_map2 : ('acc -> 'a -> 'b -> 'acc * 'c) -> 'acc -> 'a list -> 'b list -> 'acc * 'c list
|
||||
(** [fold_map2] is to [fold_map] what [List.map2] is to [List.map].
|
||||
@raise Invalid_argument if the lists do not have the same length
|
||||
@raise Invalid_argument if the lists do not have the same length.
|
||||
@since 0.16 *)
|
||||
|
||||
val fold_filter_map : ('acc -> 'a -> 'acc * 'b option) -> 'acc -> 'a list -> 'acc * 'b list
|
||||
(** [fold_filter_map f acc l] is a [fold_left]-like function, but also
|
||||
generates a list of output in a way similar to {!filter_map}
|
||||
generates a list of output in a way similar to {!filter_map}.
|
||||
@since 0.17 *)
|
||||
|
||||
val fold_flat_map : ('acc -> 'a -> 'acc * 'b list) -> 'acc -> 'a list -> 'acc * 'b list
|
||||
(** [fold_flat_map f acc l] is a [fold_left]-like function, but it also maps the
|
||||
list to a list of lists that is then [flatten]'d..
|
||||
list to a list of lists that is then [flatten]'d.
|
||||
@since 0.14 *)
|
||||
|
||||
val count : ('a -> bool) -> 'a list -> int
|
||||
(** [count f l] counts how much element of [l] comply with the function [f].
|
||||
(** [count f l] counts how much elements of [l] comply with the function [f].
|
||||
@since 1.5 *)
|
||||
|
||||
val init : int -> (int -> 'a) -> 'a t
|
||||
(** Similar to {!Array.init}
|
||||
(** [init len f] is [f 0; f 1; ...; f (len-1)].
|
||||
@raise Invalid_argument if len < 0.
|
||||
@since 0.6 *)
|
||||
|
||||
val combine : 'a list -> 'b list -> ('a * 'b) list
|
||||
(** Similar to {!List.combine} but tail-recursive.
|
||||
Transform a pair of lists into a list of pairs:
|
||||
[combine [a1; ...; an] [b1; ...; bn]] is
|
||||
[[(a1,b1); ...; (an,bn)]].
|
||||
@raise Invalid_argument if the lists have distinct lengths.
|
||||
@since 1.2 *)
|
||||
|
||||
|
|
@ -97,17 +109,21 @@ val combine_gen : 'a list -> 'b list -> ('a * 'b) gen
|
|||
@since 1.2 *)
|
||||
|
||||
val split : ('a * 'b) t -> 'a t * 'b t
|
||||
(** A tail-recursive version of {!List.split}. *)
|
||||
(** A tail-recursive version of {!List.split}.
|
||||
Transform a list of pairs into a pair of lists:
|
||||
[split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. *)
|
||||
|
||||
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
|
||||
|
||||
val compare_lengths : 'a t -> 'b t -> int
|
||||
(** equivalent to [compare (length l1) (length l2)] but more efficient.
|
||||
@since 1.5 *)
|
||||
(** Equivalent to [compare (length l1) (length l2)] but more efficient.
|
||||
Compare the lengths of two lists.
|
||||
@since 1.5 *)
|
||||
|
||||
val compare_length_with : 'a t -> int -> int
|
||||
(** equivalent to [compare (length l) x] but more efficient.
|
||||
@since 1.5 *)
|
||||
(** Equivalent to [compare (length l) x] but more efficient.
|
||||
Compare the length of a list to an integer.
|
||||
@since 1.5 *)
|
||||
|
||||
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
|
||||
|
||||
|
|
@ -115,13 +131,13 @@ val flat_map : ('a -> 'b t) -> 'a t -> 'b t
|
|||
(** Map and flatten at the same time (safe). Evaluation order is not guaranteed. *)
|
||||
|
||||
val flatten : 'a t t -> 'a t
|
||||
(** Safe flatten *)
|
||||
(** Safe flatten. Concatenate a list of lists. *)
|
||||
|
||||
val product : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
|
||||
(** Cartesian product of the two lists, with the given combinator *)
|
||||
(** Cartesian product of the two lists, with the given combinator. *)
|
||||
|
||||
val fold_product : ('c -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c
|
||||
(** Fold on the cartesian product *)
|
||||
(** Fold on the cartesian product. *)
|
||||
|
||||
val cartesian_product : 'a t t -> 'a t t
|
||||
(** Produce the cartesian product of this list of lists,
|
||||
|
|
@ -141,7 +157,7 @@ val cartesian_product : 'a t t -> 'a t t
|
|||
val map_product_l : ('a -> 'b list) -> 'a list -> 'b list list
|
||||
(** [map_product_l f l] maps each element of [l] to a list of
|
||||
objects of type ['b] using [f].
|
||||
We obtain [[l1;l2;…;ln]] where [length l=n] and [li : 'b list].
|
||||
We obtain [[l1;l2;...;ln]] where [length l=n] and [li : 'b list].
|
||||
Then, it returns all the ways of picking exactly one element per [li].
|
||||
@since 1.2 *)
|
||||
|
||||
|
|
@ -152,9 +168,9 @@ val diagonal : 'a t -> ('a * 'a) t
|
|||
val partition_map : ('a -> [<`Left of 'b | `Right of 'c | `Drop]) ->
|
||||
'a list -> 'b list * 'c list
|
||||
(** [partition_map f l] maps [f] on [l] and gather results in lists:
|
||||
- if [f x = `Left y], adds [y] to the first list
|
||||
- if [f x = `Right z], adds [z] to the second list
|
||||
- if [f x = `Drop], ignores [x]
|
||||
- if [f x = `Left y], adds [y] to the first list.
|
||||
- if [f x = `Right z], adds [z] to the second list.
|
||||
- if [f x = `Drop], ignores [x].
|
||||
@since 0.11 *)
|
||||
|
||||
val sublists_of_len :
|
||||
|
|
@ -165,14 +181,14 @@ val sublists_of_len :
|
|||
'a list list
|
||||
(** [sublists_of_len n l] returns sub-lists of [l] that have length [n].
|
||||
By default, these sub-lists are non overlapping:
|
||||
[sublists_of_len 2 [1;2;3;4;5;6]] returns [[1;2]; [3;4]; [5;6]]
|
||||
[sublists_of_len 2 [1;2;3;4;5;6]] returns [[1;2]; [3;4]; [5;6]].
|
||||
|
||||
Examples:
|
||||
|
||||
- [sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]]]
|
||||
- [sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5]]
|
||||
- [sublists_of_len 3 ~last:CCOpt.return [1;2;3;4] = [1;2;3];[4]]
|
||||
- [sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]]]
|
||||
- [sublists_of_len 2 [1;2;3;4;5;6] = [[1;2]; [3;4]; [5;6]]].
|
||||
- [sublists_of_len 2 ~offset:3 [1;2;3;4;5;6] = [1;2];[4;5]].
|
||||
- [sublists_of_len 3 ~last:CCOpt.return [1;2;3;4] = [1;2;3];[4]].
|
||||
- [sublists_of_len 2 [1;2;3;4;5] = [[1;2]; [3;4]]].
|
||||
|
||||
@param offset the number of elements skipped between two consecutive
|
||||
sub-lists. By default it is [n]. If [offset < n], the sub-lists
|
||||
|
|
@ -182,33 +198,38 @@ val sublists_of_len :
|
|||
[g'] is appended; otherwise [g] is dropped.
|
||||
If [last = CCOpt.return], it will simply keep the last group.
|
||||
By default, [last = fun _ -> None], i.e. the last group is dropped if shorter than [n].
|
||||
@raise Invalid_argument if [offset <= 0] or [n <= 0]
|
||||
@raise Invalid_argument if [offset <= 0] or [n <= 0].
|
||||
@since 1.0 *)
|
||||
|
||||
val pure : 'a -> 'a t
|
||||
(** [pure] = [return]. *)
|
||||
|
||||
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
|
||||
(** [funs <*> l] = [product (fun f x -> f x) funs l]. *)
|
||||
|
||||
val (<$>) : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [(<$>)] = [map]. *)
|
||||
|
||||
val return : 'a -> 'a t
|
||||
(** [return x] = [x]. *)
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** [l >>= f] = [flat_map f l]. *)
|
||||
|
||||
val take : int -> 'a t -> 'a t
|
||||
(** Take the [n] first elements, drop the rest *)
|
||||
(** Take the [n] first elements, drop the rest. *)
|
||||
|
||||
val drop : int -> 'a t -> 'a t
|
||||
(** Drop the [n] first elements, keep the rest *)
|
||||
(** Drop the [n] first elements, keep the rest. *)
|
||||
|
||||
val hd_tl : 'a t -> 'a * 'a t
|
||||
(** [hd_tl (x :: l)] returns [hd, l].
|
||||
@raise Failure if the list is empty
|
||||
@raise Failure if the list is empty.
|
||||
@since 0.16 *)
|
||||
|
||||
val take_drop : int -> 'a t -> 'a t * 'a t
|
||||
(** [take_drop n l] returns [l1, l2] such that [l1 @ l2 = l] and
|
||||
[length l1 = min (length l) n] *)
|
||||
[length l1 = min (length l) n]. *)
|
||||
|
||||
val take_while : ('a -> bool) -> 'a t -> 'a t
|
||||
(** @since 0.13 *)
|
||||
|
|
@ -217,12 +238,12 @@ val drop_while : ('a -> bool) -> 'a t -> 'a t
|
|||
(** @since 0.13 *)
|
||||
|
||||
val take_drop_while : ('a -> bool) -> 'a t -> 'a t * 'a t
|
||||
(** [take_drop_while p l = take_while p l, drop_while p l]
|
||||
(** [take_drop_while p l = take_while p l, drop_while p l].
|
||||
@since 1.2 *)
|
||||
|
||||
val last : int -> 'a t -> 'a t
|
||||
(** [last n l] takes the last [n] elements of [l] (or less if
|
||||
[l] doesn't have that many elements *)
|
||||
[l] doesn't have that many elements. *)
|
||||
|
||||
val head_opt : 'a t -> 'a option
|
||||
(** First element.
|
||||
|
|
@ -234,22 +255,22 @@ val last_opt : 'a t -> 'a option
|
|||
|
||||
val find_pred : ('a -> bool) -> 'a t -> 'a option
|
||||
(** [find_pred p l] finds the first element of [l] that satisfies [p],
|
||||
or returns [None] if no element satisfies [p]
|
||||
or returns [None] if no element satisfies [p].
|
||||
@since 0.11 *)
|
||||
|
||||
val find_opt : ('a -> bool) -> 'a t -> 'a option
|
||||
(** Safe version of {!find}
|
||||
(** Safe version of {!find}.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_pred_exn : ('a -> bool) -> 'a t -> 'a
|
||||
(** Unsafe version of {!find_pred}
|
||||
@raise Not_found if no such element is found
|
||||
(** Unsafe version of {!find_pred}.
|
||||
@raise Not_found if no such element is found.
|
||||
@since 0.11 *)
|
||||
|
||||
val find_map : ('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find_map f l] traverses [l], applying [f] to each element. If for
|
||||
some element [x], [f x = Some y], then [Some y] is returned. Otherwise
|
||||
the call returns [None]
|
||||
the call returns [None].
|
||||
@since 0.11 *)
|
||||
|
||||
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
|
|
@ -258,19 +279,19 @@ val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option
|
|||
|
||||
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
|
||||
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
|
||||
and [p x] holds. Otherwise returns [None] *)
|
||||
and [p x] holds. Otherwise returns [None]. *)
|
||||
|
||||
val remove : eq:('a -> 'a -> bool) -> x:'a -> 'a t -> 'a t
|
||||
(** [remove ~x l] removes every instance of [x] from [l]. Tailrec.
|
||||
@param eq equality function
|
||||
@param eq equality function.
|
||||
@since 0.11 *)
|
||||
|
||||
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
|
||||
(** Map and remove elements at the same time *)
|
||||
(** Map and remove elements at the same time. *)
|
||||
|
||||
val keep_some : 'a option t -> 'a t
|
||||
(** [filter_some l] retains only elements of the form [Some x].
|
||||
Same as [filter_map CCFun.id]
|
||||
Same as [filter_map CCFun.id].
|
||||
@since 1.3 *)
|
||||
|
||||
val keep_ok : ('a, _) Result.result t -> 'a t
|
||||
|
|
@ -288,19 +309,19 @@ val all_ok : ('a, 'err) Result.result t -> ('a t, 'err) Result.result
|
|||
@since 1.3 *)
|
||||
|
||||
val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
|
||||
(** Merges elements from both sorted list *)
|
||||
(** Merges elements from both sorted list. *)
|
||||
|
||||
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list
|
||||
(** Sort the list and remove duplicate elements *)
|
||||
(** Sort the list and remove duplicate elements. *)
|
||||
|
||||
val sorted_merge_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
|
||||
(** [sorted_merge_uniq l1 l2] merges the sorted lists [l1] and [l2] and
|
||||
removes duplicates
|
||||
removes duplicates.
|
||||
@since 0.10 *)
|
||||
|
||||
val is_sorted : cmp:('a -> 'a -> int) -> 'a list -> bool
|
||||
(** [is_sorted l] returns [true] iff [l] is sorted (according to given order)
|
||||
@param cmp the comparison function (default [Pervasives.compare])
|
||||
(** [is_sorted l] returns [true] iff [l] is sorted (according to given order).
|
||||
@param cmp the comparison function (default [Pervasives.compare]).
|
||||
@since 0.17 *)
|
||||
|
||||
val sorted_insert : cmp:('a -> 'a -> int) -> ?uniq:bool -> 'a -> 'a list -> 'a list
|
||||
|
|
@ -319,31 +340,37 @@ val sorted_insert : cmp:('a -> 'a -> int) -> ?uniq:bool -> 'a -> 'a list -> 'a l
|
|||
val uniq_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list
|
||||
(** [uniq_succ l] removes duplicate elements that occur one next to the other.
|
||||
Examples:
|
||||
[uniq_succ [1;2;1] = [1;2;1]]
|
||||
[uniq_succ [1;1;2] = [1;2]]
|
||||
[uniq_succ [1;2;1] = [1;2;1]].
|
||||
[uniq_succ [1;1;2] = [1;2]].
|
||||
@since 0.10 *)
|
||||
|
||||
val group_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list list
|
||||
(** [group_succ ~eq l] groups together consecutive elements that are equal
|
||||
according to [eq]
|
||||
according to [eq].
|
||||
@since 0.11 *)
|
||||
|
||||
(** {2 Indices} *)
|
||||
|
||||
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
|
||||
|
||||
(** Same as {!map}, but the function is applied to the index of
|
||||
the element as first argument (counting from 0), and the element
|
||||
itself as second argument. *)
|
||||
|
||||
val iteri : (int -> 'a -> unit) -> 'a t -> unit
|
||||
(** Same as {!iter}, but the function is applied to the index of
|
||||
the element as first argument (counting from 0), and the element
|
||||
itself as second argument. *)
|
||||
|
||||
val iteri2 : (int -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unit
|
||||
(** @raise Invalid_argument when lists do not have the same length
|
||||
(** @raise Invalid_argument when lists do not have the same length.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val foldi : ('b -> int -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
||||
(** Fold on list, with index *)
|
||||
(** Fold on list, with index. *)
|
||||
|
||||
val foldi2 : ('c -> int -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c
|
||||
(** Fold on two lists, with index
|
||||
@raise Invalid_argument when lists do not have the same length
|
||||
(** Fold on two lists, with index.
|
||||
@raise Invalid_argument when lists do not have the same length.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val get_at_idx : int -> 'a t -> 'a option
|
||||
|
|
@ -358,7 +385,7 @@ val nth_opt : 'a t -> int -> 'a option
|
|||
|
||||
val get_at_idx_exn : int -> 'a t -> 'a
|
||||
(** Get the i-th element, or
|
||||
@raise Not_found if the index is invalid
|
||||
@raise Not_found if the index is invalid.
|
||||
If the index is negative, it will get element starting from the end
|
||||
of the list. *)
|
||||
|
||||
|
|
@ -383,7 +410,7 @@ val remove_at_idx : int -> 'a t -> 'a t
|
|||
(** {2 Set Operators}
|
||||
|
||||
Those operations maintain the invariant that the list does not
|
||||
contain duplicates (if it already satisfies it) *)
|
||||
contain duplicates (if it already satisfies it). *)
|
||||
|
||||
val add_nodup : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t
|
||||
(** [add_nodup x set] adds [x] to [set] if it was not already present. Linear time.
|
||||
|
|
@ -394,16 +421,16 @@ val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t
|
|||
@since 0.11 *)
|
||||
|
||||
val mem : eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool
|
||||
(** Membership to the list. Linear time *)
|
||||
(** Membership to the list. Linear time. *)
|
||||
|
||||
val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool
|
||||
(** Test for inclusion *)
|
||||
(** Test for inclusion. *)
|
||||
|
||||
val uniq : eq:('a -> 'a -> bool) -> 'a t -> 'a t
|
||||
(** Remove duplicates w.r.t the equality predicate.
|
||||
Complexity is quadratic in the length of the list, but the order
|
||||
of elements is preserved. If you wish for a faster de-duplication
|
||||
but do not care about the order, use {!sort_uniq}*)
|
||||
but do not care about the order, use {!sort_uniq}. *)
|
||||
|
||||
val union : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t
|
||||
(** List union. Complexity is product of length of inputs. *)
|
||||
|
|
@ -417,29 +444,29 @@ val range_by : step:int -> int -> int -> int t
|
|||
(** [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.
|
||||
@raise Invalid_argument if [step=0]
|
||||
@raise Invalid_argument if [step=0].
|
||||
@since 0.18 *)
|
||||
|
||||
val range : int -> int -> int t
|
||||
(** [range i j] iterates on integers from [i] to [j] included . It works
|
||||
both for decreasing and increasing ranges *)
|
||||
(** [range i j] iterates on integers from [i] to [j] included. It works
|
||||
both for decreasing and increasing ranges. *)
|
||||
|
||||
val range' : int -> int -> int t
|
||||
(** Same as {!range} but the second bound is excluded.
|
||||
For instance [range' 0 5 = [0;1;2;3;4]] *)
|
||||
For instance [range' 0 5 = [0;1;2;3;4]]. *)
|
||||
|
||||
val (--) : int -> int -> int t
|
||||
(** Infix alias for [range] *)
|
||||
(** Infix alias for [range]. *)
|
||||
|
||||
val (--^) : int -> int -> int t
|
||||
(** Infix alias for [range']
|
||||
(** Infix alias for [range'].
|
||||
@since 0.17 *)
|
||||
|
||||
val replicate : int -> 'a -> 'a t
|
||||
(** Replicate the given element [n] times *)
|
||||
(** Replicate the given element [n] times. *)
|
||||
|
||||
val repeat : int -> 'a t -> 'a t
|
||||
(** Concatenate the list with itself [n] times *)
|
||||
(** Concatenate the list with itself [n] times. *)
|
||||
|
||||
(** {2 Association Lists} *)
|
||||
|
||||
|
|
@ -447,24 +474,24 @@ module Assoc : sig
|
|||
type ('a, 'b) t = ('a*'b) list
|
||||
|
||||
val get : eq:('a->'a->bool) -> 'a -> ('a,'b) t -> 'b option
|
||||
(** Find the element *)
|
||||
(** Find the element. *)
|
||||
|
||||
val get_exn : eq:('a->'a->bool) -> 'a -> ('a,'b) t -> 'b
|
||||
(** Same as [get], but unsafe
|
||||
@raise Not_found if the element is not present *)
|
||||
(** Same as [get], but unsafe.
|
||||
@raise Not_found if the element is not present. *)
|
||||
|
||||
val set : eq:('a->'a->bool) -> 'a -> 'b -> ('a,'b) t -> ('a,'b) t
|
||||
(** Add the binding into the list (erase it if already present) *)
|
||||
(** Add the binding into the list (erase it if already present). *)
|
||||
|
||||
val mem : eq:('a->'a->bool) -> 'a -> ('a,_) t -> bool
|
||||
(** [mem x l] returns [true] iff [x] is a key in [l]
|
||||
(** [mem x l] returns [true] iff [x] is a key in [l].
|
||||
@since 0.16 *)
|
||||
|
||||
val update :
|
||||
eq:('a->'a->bool) -> f:('b option -> 'b option) -> 'a -> ('a,'b) t -> ('a,'b) t
|
||||
(** [update k ~f l] updates [l] on the key [k], by calling [f (get l k)]
|
||||
and removing [k] if it returns [None], mapping [k] to [v'] if it
|
||||
returns [Some v']
|
||||
returns [Some v'].
|
||||
@since 0.16 *)
|
||||
|
||||
val remove : eq:('a->'a->bool) -> 'a -> ('a,'b) t -> ('a,'b) t
|
||||
|
|
@ -473,23 +500,23 @@ module Assoc : sig
|
|||
end
|
||||
|
||||
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b
|
||||
(** Same as [Assoc.get_exn]
|
||||
(** Same as [Assoc.get_exn].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b option
|
||||
(** Same as [Assoc.get]
|
||||
(** Same as [Assoc.get].
|
||||
@since 1.5 *)
|
||||
|
||||
val assq_opt : 'a -> ('a * 'b) t -> 'b option
|
||||
(** Safe version of {!assq}
|
||||
(** Safe version of {!assq}.
|
||||
@since 1.5 *)
|
||||
|
||||
val mem_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool
|
||||
(** Same as [Assoc.mem]
|
||||
(** Same as [Assoc.mem].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val remove_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> ('a * 'b) t
|
||||
(** Same as [Assoc.remove]
|
||||
(** Same as [Assoc.remove].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
(** {2 References on Lists}
|
||||
|
|
@ -504,20 +531,20 @@ module Ref : sig
|
|||
|
||||
val pop_exn : 'a t -> 'a
|
||||
(** Unsafe version of {!pop}.
|
||||
@raise Failure if the list is empty *)
|
||||
@raise Failure if the list is empty. *)
|
||||
|
||||
val create : unit -> 'a t
|
||||
(** Create a new list reference *)
|
||||
(** Create a new list reference. *)
|
||||
|
||||
val clear : _ t -> unit
|
||||
(** Remove all elements *)
|
||||
(** Remove all elements. *)
|
||||
|
||||
val lift : ('a list -> 'b) -> 'a t -> 'b
|
||||
(** Apply a list function to the content *)
|
||||
(** Apply a list function to the content. *)
|
||||
|
||||
val push_list : 'a t -> 'a list -> unit
|
||||
(** Add elements of the list at the beginning of the list ref. Elements
|
||||
at the end of the list will be at the beginning of the list ref *)
|
||||
at the end of the list will be at the beginning of the list ref. *)
|
||||
end
|
||||
|
||||
(** {2 Monadic Operations} *)
|
||||
|
|
@ -548,7 +575,7 @@ val random_len : int -> 'a random_gen -> 'a t random_gen
|
|||
|
||||
val random_choose : 'a t -> 'a random_gen
|
||||
(** Randomly choose an element in the list.
|
||||
@raise Not_found if the list is empty *)
|
||||
@raise Not_found if the list is empty. *)
|
||||
|
||||
val random_sequence : 'a random_gen t -> 'a t random_gen
|
||||
|
||||
|
|
@ -563,8 +590,8 @@ val of_klist : 'a klist -> 'a t
|
|||
|
||||
(** {2 Infix Operators}
|
||||
It is convenient to {!open CCList.Infix} to access the infix operators
|
||||
without cluttering the scope too much.
|
||||
|
||||
without cluttering the scope too much.
|
||||
|
||||
@since 0.16 *)
|
||||
|
||||
module Infix : sig
|
||||
|
|
|
|||
|
|
@ -10,39 +10,42 @@ type 'a t = 'a list
|
|||
val empty : 'a t
|
||||
|
||||
val is_empty : _ t -> bool
|
||||
(** [is_empty l] returns [true] iff [l = []]
|
||||
(** [is_empty l] returns [true] iff [l = []].
|
||||
@since 0.11 *)
|
||||
|
||||
val map : f:('a -> 'b) -> 'a t -> 'b t
|
||||
(** Safe version of map *)
|
||||
(** Safe version of {!List.map}. *)
|
||||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** Infix version of [map] with reversed arguments
|
||||
(** Infix version of [map] with reversed arguments.
|
||||
@since 0.5 *)
|
||||
|
||||
val cons : 'a -> 'a t -> 'a t
|
||||
(** [cons x l] is [x::l]
|
||||
(** [cons x l] is [x::l].
|
||||
@since 0.12 *)
|
||||
|
||||
val append : 'a t -> 'a t -> 'a t
|
||||
(** Safe version of append *)
|
||||
(** Safe version of {!List.append}.
|
||||
Concatenate two lists. *)
|
||||
|
||||
val cons_maybe : 'a option -> 'a t -> 'a t
|
||||
(** [cons_maybe (Some x) l] is [x :: l]
|
||||
[cons_maybe None l] is [l]
|
||||
(** [cons_maybe (Some x) l] is [x :: l].
|
||||
[cons_maybe None l] is [l].
|
||||
@since 0.13 *)
|
||||
|
||||
val (@) : 'a t -> 'a t -> 'a t
|
||||
(** Same as [append].
|
||||
Concatenate two lists. *)
|
||||
|
||||
val filter : f:('a -> bool) -> 'a t -> 'a t
|
||||
(** Safe version of {!List.filter} *)
|
||||
(** Safe version of {!List.filter}. *)
|
||||
|
||||
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
|
||||
(** Safe version of [fold_right] *)
|
||||
(** Safe version of [fold_right]. *)
|
||||
|
||||
val fold_while : f:('a -> 'b -> 'a * [`Stop | `Continue]) -> init:'a -> 'b t -> 'a
|
||||
(** Fold until a stop condition via [('a, `Stop)] is
|
||||
indicated by the accumulator
|
||||
indicated by the accumulator.
|
||||
@since 0.8 *)
|
||||
|
||||
val fold_map : f:('acc -> 'a -> 'acc * 'b) -> init:'acc -> 'a list -> 'acc * 'b list
|
||||
|
|
@ -52,21 +55,22 @@ val fold_map : f:('acc -> 'a -> 'acc * 'b) -> init:'acc -> 'a list -> 'acc * 'b
|
|||
|
||||
val fold_map2 : f:('acc -> 'a -> 'b -> 'acc * 'c) -> init:'acc -> 'a list -> 'b list -> 'acc * 'c list
|
||||
(** [fold_map2] is to [fold_map] what [List.map2] is to [List.map].
|
||||
@raise Invalid_argument if the lists do not have the same length
|
||||
@raise Invalid_argument if the lists do not have the same length.
|
||||
@since 0.16 *)
|
||||
|
||||
val fold_filter_map : f:('acc -> 'a -> 'acc * 'b option) -> init:'acc -> 'a list -> 'acc * 'b list
|
||||
(** [fold_filter_map f acc l] is a [fold_left]-like function, but also
|
||||
generates a list of output in a way similar to {!filter_map}
|
||||
generates a list of output in a way similar to {!filter_map}.
|
||||
@since 0.17 *)
|
||||
|
||||
val fold_flat_map : f:('acc -> 'a -> 'acc * 'b list) -> init:'acc -> 'a list -> 'acc * 'b list
|
||||
(** [fold_flat_map f acc l] is a [fold_left]-like function, but it also maps the
|
||||
list to a list of lists that is then [flatten]'d..
|
||||
list to a list of lists that is then [flatten]'d.
|
||||
@since 0.14 *)
|
||||
|
||||
val init : int -> f:(int -> 'a) -> 'a t
|
||||
(** Similar to {!Array.init}
|
||||
(** [init len f] is [f 0; f 1; ...; f (len-1)].
|
||||
@raise Invalid_argument if len < 0.
|
||||
@since 0.6 *)
|
||||
|
||||
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
|
||||
|
|
@ -77,13 +81,13 @@ val flat_map : f:('a -> 'b t) -> 'a t -> 'b t
|
|||
(** Map and flatten at the same time (safe). Evaluation order is not guaranteed. *)
|
||||
|
||||
val flatten : 'a t t -> 'a t
|
||||
(** Safe flatten *)
|
||||
(** Safe flatten. Concatenate a list of lists. *)
|
||||
|
||||
val product : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
|
||||
(** Cartesian product of the two lists, with the given combinator *)
|
||||
(** Cartesian product of the two lists, with the given combinator. *)
|
||||
|
||||
val fold_product : f:('c -> 'a -> 'b -> 'c) -> init:'c -> 'a t -> 'b t -> 'c
|
||||
(** Fold on the cartesian product *)
|
||||
(** Fold on the cartesian product. *)
|
||||
|
||||
val diagonal : 'a t -> ('a * 'a) t
|
||||
(** All pairs of distinct positions of the list. [list_diagonal l] will
|
||||
|
|
@ -92,9 +96,9 @@ val diagonal : 'a t -> ('a * 'a) t
|
|||
val partition_map : f:('a -> [<`Left of 'b | `Right of 'c | `Drop]) ->
|
||||
'a list -> 'b list * 'c list
|
||||
(** [partition_map f l] maps [f] on [l] and gather results in lists:
|
||||
- if [f x = `Left y], adds [y] to the first list
|
||||
- if [f x = `Right z], adds [z] to the second list
|
||||
- if [f x = `Drop], ignores [x]
|
||||
- if [f x = `Left y], adds [y] to the first list.
|
||||
- if [f x = `Right z], adds [z] to the second list.
|
||||
- if [f x = `Drop], ignores [x].
|
||||
@since 0.11 *)
|
||||
|
||||
val sublists_of_len :
|
||||
|
|
@ -112,29 +116,34 @@ val sublists_of_len :
|
|||
@since 1.5 *)
|
||||
|
||||
val pure : 'a -> 'a t
|
||||
(** [pure] = [return]. *)
|
||||
|
||||
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
|
||||
(** [funs <*> l] = [product fun f x -> f x) funs l]. *)
|
||||
|
||||
val (<$>) : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [(<$>)] = [map]. *)
|
||||
|
||||
val return : 'a -> 'a t
|
||||
(** [return x] = [x]. *)
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** [l >>= f] = [flat_map f l]. *)
|
||||
|
||||
val take : int -> 'a t -> 'a t
|
||||
(** Take the [n] first elements, drop the rest *)
|
||||
(** Take the [n] first elements, drop the rest. *)
|
||||
|
||||
val drop : int -> 'a t -> 'a t
|
||||
(** Drop the [n] first elements, keep the rest *)
|
||||
(** Drop the [n] first elements, keep the rest. *)
|
||||
|
||||
val hd_tl : 'a t -> 'a * 'a t
|
||||
(** [hd_tl (x :: l)] returns [hd, l].
|
||||
@raise Failure if the list is empty
|
||||
@raise Failure if the list is empty.
|
||||
@since 0.16 *)
|
||||
|
||||
val take_drop : int -> 'a t -> 'a t * 'a t
|
||||
(** [take_drop n l] returns [l1, l2] such that [l1 @ l2 = l] and
|
||||
[length l1 = min (length l) n] *)
|
||||
[length l1 = min (length l) n]. *)
|
||||
|
||||
val take_while : f:('a -> bool) -> 'a t -> 'a t
|
||||
(** @since 0.13 *)
|
||||
|
|
@ -144,7 +153,7 @@ val drop_while : f:('a -> bool) -> 'a t -> 'a t
|
|||
|
||||
val last : int -> 'a t -> 'a t
|
||||
(** [last n l] takes the last [n] elements of [l] (or less if
|
||||
[l] doesn't have that many elements *)
|
||||
[l] doesn't have that many elements. *)
|
||||
|
||||
val head_opt : 'a t -> 'a option
|
||||
(** First element.
|
||||
|
|
@ -156,18 +165,18 @@ val last_opt : 'a t -> 'a option
|
|||
|
||||
val find_pred : f:('a -> bool) -> 'a t -> 'a option
|
||||
(** [find_pred p l] finds the first element of [l] that satisfies [p],
|
||||
or returns [None] if no element satisfies [p]
|
||||
or returns [None] if no element satisfies [p].
|
||||
@since 0.11 *)
|
||||
|
||||
val find_pred_exn : f:('a -> bool) -> 'a t -> 'a
|
||||
(** Unsafe version of {!find_pred}
|
||||
@raise Not_found if no such element is found
|
||||
(** Unsafe version of {!find_pred}.
|
||||
@raise Not_found if no such element is found.
|
||||
@since 0.11 *)
|
||||
|
||||
val find_map : f:('a -> 'b option) -> 'a t -> 'b option
|
||||
(** [find_map f l] traverses [l], applying [f] to each element. If for
|
||||
some element [x], [f x = Some y], then [Some y] is returned. Otherwise
|
||||
the call returns [None]
|
||||
the call returns [None].
|
||||
@since 0.11 *)
|
||||
|
||||
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
|
||||
|
|
@ -176,30 +185,30 @@ val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
|
|||
|
||||
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option
|
||||
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
|
||||
and [p x] holds. Otherwise returns [None] *)
|
||||
and [p x] holds. Otherwise returns [None]. *)
|
||||
|
||||
val remove : eq:('a -> 'a -> bool) -> key:'a -> 'a t -> 'a t
|
||||
(** [remove ~key l] removes every instance of [key] from [l]. Tailrec.
|
||||
@param eq equality function
|
||||
@param eq equality function.
|
||||
@since 0.11 *)
|
||||
|
||||
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t
|
||||
(** Map and remove elements at the same time *)
|
||||
(** Map and remove elements at the same time. *)
|
||||
|
||||
val sorted_merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
|
||||
(** Merges elements from both sorted list *)
|
||||
(** Merges elements from both sorted list. *)
|
||||
|
||||
val sort_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list
|
||||
(** Sort the list and remove duplicate elements *)
|
||||
(** Sort the list and remove duplicate elements. *)
|
||||
|
||||
val sorted_merge_uniq : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
|
||||
(** [sorted_merge_uniq l1 l2] merges the sorted lists [l1] and [l2] and
|
||||
removes duplicates
|
||||
removes duplicates.
|
||||
@since 0.10 *)
|
||||
|
||||
val is_sorted : cmp:('a -> 'a -> int) -> 'a list -> bool
|
||||
(** [is_sorted l] returns [true] iff [l] is sorted (according to given order)
|
||||
@param cmp the comparison function (default [Pervasives.compare])
|
||||
(** [is_sorted l] returns [true] iff [l] is sorted (according to given order).
|
||||
@param cmp the comparison function (default [Pervasives.compare]).
|
||||
@since 0.17 *)
|
||||
|
||||
val sorted_insert : cmp:('a -> 'a -> int) -> ?uniq:bool -> 'a -> 'a list -> 'a list
|
||||
|
|
@ -218,46 +227,63 @@ val sorted_insert : cmp:('a -> 'a -> int) -> ?uniq:bool -> 'a -> 'a list -> 'a l
|
|||
val uniq_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list
|
||||
(** [uniq_succ l] removes duplicate elements that occur one next to the other.
|
||||
Examples:
|
||||
[uniq_succ [1;2;1] = [1;2;1]]
|
||||
[uniq_succ [1;1;2] = [1;2]]
|
||||
[uniq_succ [1;2;1] = [1;2;1]].
|
||||
[uniq_succ [1;1;2] = [1;2]].
|
||||
@since 0.10 *)
|
||||
|
||||
val group_succ : eq:('a -> 'a -> bool) -> 'a list -> 'a list list
|
||||
(** [group_succ ~eq l] groups together consecutive elements that are equal
|
||||
according to [eq]
|
||||
according to [eq].
|
||||
@since 0.11 *)
|
||||
|
||||
(** {2 Indices} *)
|
||||
|
||||
val mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b t
|
||||
(** Same as {!map}, but the function is applied to the index of
|
||||
the element as first argument (counting from 0), and the element
|
||||
itself as second argument. *)
|
||||
|
||||
val iteri : f:(int -> 'a -> unit) -> 'a t -> unit
|
||||
(** Same as {!iter}, but the function is applied to the index of
|
||||
the element as first argument (counting from 0), and the element
|
||||
itself as second argument. *)
|
||||
|
||||
val foldi : f:('b -> int -> 'a -> 'b) -> init:'b -> 'a t -> 'b
|
||||
(** Fold on list, with index *)
|
||||
(** Fold on list, with index. *)
|
||||
|
||||
val get_at_idx : int -> 'a t -> 'a option
|
||||
(** Get by index in the list.
|
||||
If the index is negative, it will get element starting from the end
|
||||
of the list. *)
|
||||
|
||||
val get_at_idx_exn : int -> 'a t -> 'a
|
||||
(** Get the i-th element, or
|
||||
@raise Not_found if the index is invalid *)
|
||||
@raise Not_found if the index is invalid.
|
||||
If the index is negative, it will get element starting from the end
|
||||
of the list. *)
|
||||
|
||||
val set_at_idx : int -> 'a -> 'a t -> 'a t
|
||||
(** Set i-th element (removes the old one), or does nothing if
|
||||
index is too high *)
|
||||
index is too high.
|
||||
If the index is negative, it will set element starting from the end
|
||||
of the list. *)
|
||||
|
||||
val insert_at_idx : int -> 'a -> 'a t -> 'a t
|
||||
(** Insert at i-th position, between the two existing elements. If the
|
||||
index is too high, append at the end of the list *)
|
||||
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. *)
|
||||
|
||||
val remove_at_idx : int -> 'a t -> 'a t
|
||||
(** Remove element at given index. Does nothing if the index is
|
||||
too high. *)
|
||||
too high.
|
||||
If the index is negative, it will remove element starting from the end
|
||||
of the list. *)
|
||||
|
||||
(** {2 Set Operators}
|
||||
|
||||
Those operations maintain the invariant that the list does not
|
||||
contain duplicates (if it already satisfies it) *)
|
||||
contain duplicates (if it already satisfies it). *)
|
||||
|
||||
val add_nodup : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t
|
||||
(** [add_nodup x set] adds [x] to [set] if it was not already present. Linear time.
|
||||
|
|
@ -268,16 +294,16 @@ val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t
|
|||
@since 0.11 *)
|
||||
|
||||
val mem : eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool
|
||||
(** Membership to the list. Linear time *)
|
||||
(** Membership to the list. Linear time. *)
|
||||
|
||||
val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool
|
||||
(** Test for inclusion *)
|
||||
(** Test for inclusion. *)
|
||||
|
||||
val uniq : eq:('a -> 'a -> bool) -> 'a t -> 'a t
|
||||
(** Remove duplicates w.r.t the equality predicate.
|
||||
Complexity is quadratic in the length of the list, but the order
|
||||
of elements is preserved. If you wish for a faster de-duplication
|
||||
but do not care about the order, use {!sort_uniq}*)
|
||||
but do not care about the order, use {!sort_uniq}. *)
|
||||
|
||||
val union : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t
|
||||
(** List union. Complexity is product of length of inputs. *)
|
||||
|
|
@ -291,29 +317,29 @@ val range_by : step:int -> int -> int -> int t
|
|||
(** [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.
|
||||
@raise Invalid_argument if [step=0]
|
||||
@raise Invalid_argument if [step=0].
|
||||
@since 0.18 *)
|
||||
|
||||
val range : int -> int -> int t
|
||||
(** [range i j] iterates on integers from [i] to [j] included . It works
|
||||
both for decreasing and increasing ranges *)
|
||||
(** [range i j] iterates on integers from [i] to [j] included. It works
|
||||
both for decreasing and increasing ranges. *)
|
||||
|
||||
val range' : int -> int -> int t
|
||||
(** Same as {!range} but the second bound is excluded.
|
||||
For instance [range' 0 5 = [0;1;2;3;4]] *)
|
||||
For instance [range' 0 5 = [0;1;2;3;4]]. *)
|
||||
|
||||
val (--) : int -> int -> int t
|
||||
(** Infix alias for [range] *)
|
||||
(** Infix alias for [range]. *)
|
||||
|
||||
val (--^) : int -> int -> int t
|
||||
(** Infix alias for [range']
|
||||
(** Infix alias for [range'].
|
||||
@since 0.17 *)
|
||||
|
||||
val replicate : int -> 'a -> 'a t
|
||||
(** Replicate the given element [n] times *)
|
||||
(** Replicate the given element [n] times. *)
|
||||
|
||||
val repeat : int -> 'a t -> 'a t
|
||||
(** Concatenate the list with itself [n] times *)
|
||||
(** Concatenate the list with itself [n] times. *)
|
||||
|
||||
(** {2 Association Lists} *)
|
||||
|
||||
|
|
@ -321,24 +347,24 @@ module Assoc : sig
|
|||
type ('a, 'b) t = ('a*'b) list
|
||||
|
||||
val get : eq:('a->'a->bool) -> 'a -> ('a,'b) t -> 'b option
|
||||
(** Find the element *)
|
||||
(** Find the element. *)
|
||||
|
||||
val get_exn : eq:('a->'a->bool) -> 'a -> ('a,'b) t -> 'b
|
||||
(** Same as [get], but unsafe
|
||||
@raise Not_found if the element is not present *)
|
||||
(** Same as [get], but unsafe.
|
||||
@raise Not_found if the element is not present. *)
|
||||
|
||||
val set : eq:('a->'a->bool) -> 'a -> 'b -> ('a,'b) t -> ('a,'b) t
|
||||
(** Add the binding into the list (erase it if already present) *)
|
||||
(** Add the binding into the list (erase it if already present). *)
|
||||
|
||||
val mem : eq:('a->'a->bool) -> 'a -> ('a,_) t -> bool
|
||||
(** [mem x l] returns [true] iff [x] is a key in [l]
|
||||
(** [mem x l] returns [true] iff [x] is a key in [l].
|
||||
@since 0.16 *)
|
||||
|
||||
val update :
|
||||
eq:('a->'a->bool) -> f:('b option -> 'b option) -> 'a -> ('a,'b) t -> ('a,'b) t
|
||||
(** [update k ~f l] updates [l] on the key [k], by calling [f (get l k)]
|
||||
and removing [k] if it returns [None], mapping [k] to [v'] if it
|
||||
returns [Some v']
|
||||
returns [Some v'].
|
||||
@since 0.16 *)
|
||||
|
||||
val remove : eq:('a->'a->bool) -> 'a -> ('a,'b) t -> ('a,'b) t
|
||||
|
|
@ -347,23 +373,23 @@ module Assoc : sig
|
|||
end
|
||||
|
||||
val assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b
|
||||
(** Same as [Assoc.get_exn]
|
||||
(** Same as [Assoc.get_exn].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val assoc_opt : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> 'b option
|
||||
(** Same as [Assoc.get]
|
||||
(** Same as [Assoc.get].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val assq_opt : 'a -> ('a * 'b) t -> 'b option
|
||||
(** Safe version of {!assq}
|
||||
(** Safe version of {!assq}.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val mem_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool
|
||||
(** Same as [Assoc.mem]
|
||||
(** Same as [Assoc.mem].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val remove_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * 'b) t -> ('a * 'b) t
|
||||
(** Same as [Assoc.remove]
|
||||
(** Same as [Assoc.remove].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
(** {2 References on Lists}
|
||||
|
|
@ -378,20 +404,20 @@ module Ref : sig
|
|||
|
||||
val pop_exn : 'a t -> 'a
|
||||
(** Unsafe version of {!pop}.
|
||||
@raise Failure if the list is empty *)
|
||||
@raise Failure if the list is empty. *)
|
||||
|
||||
val create : unit -> 'a t
|
||||
(** Create a new list reference *)
|
||||
(** Create a new list reference. *)
|
||||
|
||||
val clear : _ t -> unit
|
||||
(** Remove all elements *)
|
||||
(** Remove all elements. *)
|
||||
|
||||
val lift : ('a list -> 'b) -> 'a t -> 'b
|
||||
(** Apply a list function to the content *)
|
||||
(** Apply a list function to the content. *)
|
||||
|
||||
val push_list : 'a t -> 'a list -> unit
|
||||
(** Add elements of the list at the beginning of the list ref. Elements
|
||||
at the end of the list will be at the beginning of the list ref *)
|
||||
at the end of the list will be at the beginning of the list ref. *)
|
||||
end
|
||||
|
||||
(** {2 Monadic Operations} *)
|
||||
|
|
@ -428,7 +454,7 @@ val random_len : int -> 'a random_gen -> 'a t random_gen
|
|||
|
||||
val random_choose : 'a t -> 'a random_gen
|
||||
(** Randomly choose an element in the list.
|
||||
@raise Not_found if the list is empty *)
|
||||
@raise Not_found if the list is empty. *)
|
||||
|
||||
val random_sequence : 'a random_gen t -> 'a t random_gen
|
||||
|
||||
|
|
@ -443,7 +469,7 @@ val of_klist : 'a klist -> 'a t
|
|||
|
||||
(** {2 Infix Operators}
|
||||
It is convenient to {!open CCList.Infix} to access the infix operators
|
||||
without cluttering the scope too much.
|
||||
without cluttering the scope too much.
|
||||
|
||||
@since 0.16 *)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ module type S = sig
|
|||
include Map.S
|
||||
|
||||
val get : key -> 'a t -> 'a option
|
||||
(** Safe version of {!find} *)
|
||||
(** Safe version of {!find}. *)
|
||||
|
||||
val get_or : key -> 'a t -> default:'a -> 'a
|
||||
(** [get_or k m ~default] returns the value associated to [k] if present,
|
||||
and returns [default] otherwise (if [k] doesn't belong in [m])
|
||||
and returns [default] otherwise (if [k] doesn't belong in [m]).
|
||||
@since 0.16 *)
|
||||
|
||||
val update : key -> ('a option -> 'a option) -> 'a t -> 'a t
|
||||
|
|
@ -30,19 +30,19 @@ module type S = sig
|
|||
[add k v' m] is returned. *)
|
||||
|
||||
val choose_opt : 'a t -> (key * 'a) option
|
||||
(** Safe version of {!choose}
|
||||
(** Safe version of {!choose}.
|
||||
@since 1.5 *)
|
||||
|
||||
val min_binding_opt : 'a t -> (key * 'a) option
|
||||
(** Safe version of {!min_binding}
|
||||
(** Safe version of {!min_binding}.
|
||||
@since 1.5 *)
|
||||
|
||||
val max_binding_opt : 'a t -> (key * 'a) option
|
||||
(** Safe version of {!max_binding}
|
||||
(** Safe version of {!max_binding}.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_opt : key -> 'a t -> 'a option
|
||||
(** Safe version of {!find}
|
||||
(** Safe version of {!find}.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_first : (key -> bool) -> 'a t -> key * 'a
|
||||
|
|
@ -51,7 +51,7 @@ module type S = sig
|
|||
@since 1.5 *)
|
||||
|
||||
val find_first_opt : (key -> bool) -> 'a t -> (key * 'a) option
|
||||
(** Safe version of {!find_first}
|
||||
(** Safe version of {!find_first}.
|
||||
@since 1.5 *)
|
||||
|
||||
val merge_safe :
|
||||
|
|
@ -62,11 +62,11 @@ module type S = sig
|
|||
|
||||
val union : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t
|
||||
(** Union of both maps, using the function to combine bindings
|
||||
that belong to both inputs
|
||||
that belong to both inputs.
|
||||
@since 1.4 *)
|
||||
|
||||
val of_seq : (key * 'a) sequence -> 'a t
|
||||
(** Same as {!of_list} *)
|
||||
(** Same as {!of_list}. *)
|
||||
|
||||
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
|
||||
(** @since 0.14 *)
|
||||
|
|
@ -83,11 +83,11 @@ module type S = sig
|
|||
(** @since 0.14 *)
|
||||
|
||||
val keys : _ t -> key sequence
|
||||
(** Iterate on keys only
|
||||
(** Iterate on keys only.
|
||||
@since 0.15 *)
|
||||
|
||||
val values : 'a t -> 'a sequence
|
||||
(** Iterate on values only
|
||||
(** Iterate on values only.
|
||||
@since 0.15 *)
|
||||
|
||||
val to_list : 'a t -> (key * 'a) list
|
||||
|
|
|
|||
|
|
@ -8,19 +8,21 @@ include module type of Random
|
|||
type state = Random.State.t
|
||||
|
||||
type 'a t = state -> 'a
|
||||
(** Random generator for values of type ['a] *)
|
||||
(** Random generator for values of type ['a]. *)
|
||||
|
||||
type 'a random_gen = 'a t
|
||||
|
||||
val return : 'a -> 'a t
|
||||
(** [return x] is the generator that always returns [x].
|
||||
Example: [let random_int = return 4 (* fair dice roll *)] *)
|
||||
Example: [let random_int = return 4 (* fair dice roll *)]. *)
|
||||
|
||||
val flat_map : ('a -> 'b t) -> 'a t -> 'b t
|
||||
(** [flat_map f g st] = [f (g st) st]. *)
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
|
||||
val map : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [map f g st] = [f (g st)]. *)
|
||||
|
||||
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
|
||||
|
||||
|
|
@ -43,41 +45,41 @@ val choose : 'a t list -> 'a option t
|
|||
|
||||
val choose_exn : 'a t list -> 'a t
|
||||
(** Same as {!choose} but without option.
|
||||
@raise Invalid_argument if the list is empty *)
|
||||
@raise Invalid_argument if the list is empty. *)
|
||||
|
||||
val choose_array : 'a t array -> 'a option t
|
||||
|
||||
val choose_return : 'a list -> 'a t
|
||||
(** Choose among the list
|
||||
(** Choose among the list.
|
||||
@raise Invalid_argument if the list is empty *)
|
||||
|
||||
val replicate : int -> 'a t -> 'a list t
|
||||
(** [replicate n g] makes a list of [n] elements which are all generated
|
||||
randomly using [g] *)
|
||||
randomly using [g]. *)
|
||||
|
||||
val sample_without_replacement:
|
||||
compare:('a -> 'a -> int) -> int -> 'a t -> 'a list t
|
||||
(** [sample_without_replacement n g] makes a list of [n] elements which are all
|
||||
generated randomly using [g] with the added constraint that none of the generated
|
||||
random values are equal
|
||||
@raise Invalid_argument if [n <= 0]
|
||||
random values are equal.
|
||||
@raise Invalid_argument if [n <= 0].
|
||||
@since 0.15 *)
|
||||
|
||||
val list_seq : 'a t list -> 'a list t
|
||||
(** Build random lists from lists of random generators
|
||||
(** Build random lists from lists of random generators.
|
||||
@since 0.4 *)
|
||||
|
||||
exception Pick_from_empty
|
||||
(** @since 0.16 *)
|
||||
|
||||
val pick_list : 'a list -> 'a t
|
||||
(** Pick an element at random from the list
|
||||
@raise Pick_from_empty if the list is empty
|
||||
(** Pick an element at random from the list.
|
||||
@raise Pick_from_empty if the list is empty.
|
||||
@since 0.16 *)
|
||||
|
||||
val pick_array : 'a array -> 'a t
|
||||
(** Pick an element at random from the array
|
||||
@raise Pick_from_empty if the array is empty
|
||||
(** Pick an element at random from the array.
|
||||
@raise Pick_from_empty if the array is empty.
|
||||
@since 0.16 *)
|
||||
|
||||
val small_int : int t
|
||||
|
|
@ -85,14 +87,14 @@ val small_int : int t
|
|||
val int : int -> int t
|
||||
|
||||
val int_range : int -> int -> int t
|
||||
(** Inclusive range *)
|
||||
(** Inclusive range. *)
|
||||
|
||||
val small_float : float t
|
||||
(** A reasonably small float.
|
||||
@since 0.6.1 *)
|
||||
|
||||
val float : float -> float t
|
||||
(** Random float within the given range
|
||||
(** Random float within the given range.
|
||||
@since 0.6.1 *)
|
||||
|
||||
val float_range : float -> float -> float t
|
||||
|
|
@ -101,25 +103,25 @@ val float_range : float -> float -> float t
|
|||
|
||||
val split : int -> (int * int) option t
|
||||
(** Split a positive value [n] into [n1,n2] where [n = n1 + n2].
|
||||
@return [None] if the value is too small *)
|
||||
@return [None] if the value is too small. *)
|
||||
|
||||
val split_list : int -> len:int -> int list option t
|
||||
(** Split a value [n] into a list of values whose sum is [n]
|
||||
and whose length is [length]. The list is never empty and does not
|
||||
contain [0].
|
||||
@raise Invalid_argument if [len <= 1]
|
||||
@return [None] if the value is too small *)
|
||||
@raise Invalid_argument if [len <= 1].
|
||||
@return [None] if the value is too small. *)
|
||||
|
||||
val retry : ?max:int -> 'a option t -> 'a option t
|
||||
(** [retry g] calls [g] until it returns some value, or until the maximum
|
||||
number of retries was reached. If [g] fails,
|
||||
then it counts for one iteration, and the generator retries.
|
||||
@param max: maximum number of retries. Default [10] *)
|
||||
@param max: maximum number of retries. Default [10]. *)
|
||||
|
||||
val try_successively : 'a option t list -> 'a option t
|
||||
(** [try_successively l] tries each generator of [l], one after the other.
|
||||
If some generator succeeds its result is returned, else the
|
||||
next generator is tried *)
|
||||
next generator is tried. *)
|
||||
|
||||
val (<?>) : 'a option t -> 'a option t -> 'a option t
|
||||
(** [a <?> b] is a choice operator. It first tries [a], and returns its
|
||||
|
|
@ -133,9 +135,9 @@ val fix :
|
|||
(** Recursion combinators, for building recursive values.
|
||||
The integer generator is used to provide fuel. The [sub_] generators
|
||||
should use their arguments only once!
|
||||
@param sub1 cases that recurse on one value
|
||||
@param sub2 cases that use the recursive gen twice
|
||||
@param subn cases that use a list of recursive cases *)
|
||||
@param sub1 cases that recurse on one value.
|
||||
@param sub2 cases that use the recursive gen twice.
|
||||
@param subn cases that use a list of recursive cases. *)
|
||||
|
||||
(** {6 Applicative} *)
|
||||
|
||||
|
|
@ -146,7 +148,7 @@ val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
|
|||
(** {6 Run a generator} *)
|
||||
|
||||
val run : ?st:state -> 'a t -> 'a
|
||||
(** Using a random state (possibly the one in argument) run a generator *)
|
||||
(** Using a random state (possibly the one in argument) run a generator. *)
|
||||
|
||||
(**/**)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,35 +15,35 @@ module type S = sig
|
|||
include Set.S
|
||||
|
||||
val min_elt_opt : t -> elt option
|
||||
(** Safe version of {!min_elt}
|
||||
(** Safe version of {!min_elt}.
|
||||
@since 1.5 *)
|
||||
|
||||
val max_elt_opt : t -> elt option
|
||||
(** Safe version of {!max_elt}
|
||||
(** Safe version of {!max_elt}.
|
||||
@since 1.5 *)
|
||||
|
||||
val choose_opt : t -> elt option
|
||||
(** Safe version of {!choose}
|
||||
(** Safe version of {!choose}.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_opt : elt -> t -> elt option
|
||||
(** Safe version of {!find}
|
||||
(** Safe version of {!find}.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_first : (elt -> bool) -> t -> elt
|
||||
(** Find minimum element satisfying predicate
|
||||
(** Find minimum element satisfying predicate.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_first_opt : (elt -> bool) -> t -> elt option
|
||||
(** Safe version of {!find_first}
|
||||
(** Safe version of {!find_first}.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_last : (elt -> bool) -> t -> elt
|
||||
(** Find maximum element satisfying predicate
|
||||
(** Find maximum element satisfying predicate.
|
||||
@since 1.5 *)
|
||||
|
||||
val find_last_opt : (elt -> bool) -> t -> elt option
|
||||
(** Safe version of {!find_last}
|
||||
(** Safe version of {!find_last}.
|
||||
@since 1.5 *)
|
||||
|
||||
val of_seq : elt sequence -> t
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ module type S = sig
|
|||
val blit : t -> int -> Bytes.t -> int -> int -> unit
|
||||
(** Similar to {!String.blit}.
|
||||
Compatible with the [-safe-string] option.
|
||||
@raise Invalid_argument if indices are not valid *)
|
||||
@raise Invalid_argument if indices are not valid. *)
|
||||
|
||||
(*
|
||||
val blit_immut : t -> int -> t -> int -> int -> string
|
||||
(** Immutable version of {!blit}, returning a new string.
|
||||
[blit a i b j len] is the same as [b], but in which
|
||||
the range [j, ..., j+len] is replaced by [a.[i], ..., a.[i + len]].
|
||||
@raise Invalid_argument if indices are not valid *)
|
||||
@raise Invalid_argument if indices are not valid. *)
|
||||
*)
|
||||
|
||||
val fold : ('a -> char -> 'a) -> 'a -> t -> 'a
|
||||
|
|
@ -42,11 +42,13 @@ module type S = sig
|
|||
val to_list : t -> char list
|
||||
|
||||
val pp_buf : Buffer.t -> t -> unit
|
||||
(** Renamed from [pp] @since NEXT_RELEASE *)
|
||||
(** Renamed from [pp].
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val pp : Format.formatter -> t -> unit
|
||||
(** Print the string within quotes
|
||||
Renamed from [print] @since NEXT_RELEASE *)
|
||||
(** Print the string within quotes.
|
||||
Renamed from [print].
|
||||
@since NEXT_RELEASE *)
|
||||
end
|
||||
|
||||
(** {2 Strings} *)
|
||||
|
|
@ -72,7 +74,7 @@ val init : int -> (int -> char) -> string
|
|||
*)
|
||||
|
||||
val rev : string -> string
|
||||
(** [rev s] returns the reverse of [s]
|
||||
(** [rev s] returns the reverse of [s].
|
||||
@since 0.17 *)
|
||||
|
||||
(*$Q
|
||||
|
|
@ -89,8 +91,8 @@ val rev : string -> string
|
|||
val pad : ?side:[`Left|`Right] -> ?c:char -> int -> string -> string
|
||||
(** [pad n str] ensures that [str] is at least [n] bytes long,
|
||||
and pads it on the [side] with [c] if it's not the case.
|
||||
@param side determines where padding occurs (default: [`Left])
|
||||
@param c the char used to pad (default: ' ')
|
||||
@param side determines where padding occurs (default: [`Left]).
|
||||
@param c the char used to pad (default: ' ').
|
||||
@since 0.17 *)
|
||||
|
||||
(*$= & ~printer:Q.Print.string
|
||||
|
|
@ -103,7 +105,7 @@ val pad : ?side:[`Left|`Right] -> ?c:char -> int -> string -> string
|
|||
*)
|
||||
|
||||
val of_char : char -> string
|
||||
(** [of_char 'a' = "a"]
|
||||
(** [of_char 'a' = "a"].
|
||||
@since 0.19 *)
|
||||
|
||||
val of_gen : char gen -> string
|
||||
|
|
@ -138,13 +140,13 @@ val find : ?start:int -> sub:string -> string -> int
|
|||
val find_all : ?start:int -> sub:string -> string -> int gen
|
||||
(** [find_all ~sub s] finds all occurrences of [sub] in [s], even overlapping
|
||||
instances.
|
||||
@param start starting position in [s]
|
||||
@param start starting position in [s].
|
||||
@since 0.17 *)
|
||||
|
||||
val find_all_l : ?start:int -> sub:string -> string -> int list
|
||||
(** [find_all ~sub s] finds all occurrences of [sub] in [s] and returns
|
||||
them in a list
|
||||
@param start starting position in [s]
|
||||
them in a list.
|
||||
@param start starting position in [s].
|
||||
@since 0.17 *)
|
||||
|
||||
(*$= & ~printer:Q.Print.(list int)
|
||||
|
|
@ -155,7 +157,7 @@ val find_all_l : ?start:int -> sub:string -> string -> int list
|
|||
*)
|
||||
|
||||
val mem : ?start:int -> sub:string -> string -> bool
|
||||
(** [mem ~sub s] is true iff [sub] is a substring of [s]
|
||||
(** [mem ~sub s] is true iff [sub] is a substring of [s].
|
||||
@since 0.12 *)
|
||||
|
||||
(*$T
|
||||
|
|
@ -165,7 +167,7 @@ val mem : ?start:int -> sub:string -> string -> bool
|
|||
|
||||
val rfind : sub:string -> string -> int
|
||||
(** Find [sub] in string from the right, returns its first index or [-1].
|
||||
Should only be used with very small [sub]
|
||||
Should only be used with very small [sub].
|
||||
@since 0.12 *)
|
||||
|
||||
(*$= & ~printer:string_of_int
|
||||
|
|
@ -183,14 +185,14 @@ val rfind : sub:string -> string -> int
|
|||
*)
|
||||
|
||||
val replace : ?which:[`Left|`Right|`All] -> sub:string -> by:string -> string -> string
|
||||
(** [replace ~sub ~by s] replaces some occurrences of [sub] by [by] in [s]
|
||||
(** [replace ~sub ~by s] replaces some occurrences of [sub] by [by] in [s].
|
||||
@param which decides whether the occurrences to replace are:
|
||||
{ul
|
||||
{- [`Left] first occurrence from the left (beginning)}
|
||||
{- [`Right] first occurrence from the right (end)}
|
||||
{- [`All] all occurrences (default)}
|
||||
}
|
||||
@raise Invalid_argument if [sub = ""]
|
||||
@raise Invalid_argument if [sub = ""].
|
||||
@since 0.14 *)
|
||||
|
||||
(*$= & ~printer:CCFun.id
|
||||
|
|
@ -206,13 +208,13 @@ val replace : ?which:[`Left|`Right|`All] -> sub:string -> by:string -> string ->
|
|||
val is_sub : sub:string -> int -> string -> int -> len:int -> bool
|
||||
(** [is_sub ~sub i s j ~len] returns [true] iff the substring of
|
||||
[sub] starting at position [i] and of length [len] is a substring
|
||||
of [s] starting at position [j] *)
|
||||
of [s] starting at position [j]. *)
|
||||
|
||||
val repeat : string -> int -> string
|
||||
(** The same string, repeated n times *)
|
||||
(** The same string, repeated n times. *)
|
||||
|
||||
val prefix : pre:string -> string -> bool
|
||||
(** [prefix ~pre s] returns [true] iff [pre] is a prefix of [s] *)
|
||||
(** [prefix ~pre s] returns [true] iff [pre] is a prefix of [s]. *)
|
||||
|
||||
(*$T
|
||||
prefix ~pre:"aab" "aabcd"
|
||||
|
|
@ -225,7 +227,7 @@ val prefix : pre:string -> string -> bool
|
|||
*)
|
||||
|
||||
val suffix : suf:string -> string -> bool
|
||||
(** [suffix ~suf s] returns [true] iff [suf] is a suffix of [s]
|
||||
(** [suffix ~suf s] returns [true] iff [suf] is a suffix of [s].
|
||||
@since 0.7 *)
|
||||
|
||||
(*$T
|
||||
|
|
@ -237,8 +239,8 @@ val suffix : suf:string -> string -> bool
|
|||
*)
|
||||
|
||||
val chop_prefix : pre:string -> string -> string option
|
||||
(** [chop_pref ~pre s] removes [pre] from [s] if [pre] really is a prefix
|
||||
of [s], returns [None] otherwise
|
||||
(** [chop_prefix ~pre s] removes [pre] from [s] if [pre] really is a prefix
|
||||
of [s], returns [None] otherwise.
|
||||
@since 0.17 *)
|
||||
|
||||
(*$= & ~printer:Q.Print.(option string)
|
||||
|
|
@ -249,7 +251,7 @@ val chop_prefix : pre:string -> string -> string option
|
|||
|
||||
val chop_suffix : suf:string -> string -> string option
|
||||
(** [chop_suffix ~suf s] removes [suf] from [s] if [suf] really is a suffix
|
||||
of [s], returns [None] otherwise
|
||||
of [s], returns [None] otherwise.
|
||||
@since 0.17 *)
|
||||
|
||||
(*$= & ~printer:Q.Print.(option string)
|
||||
|
|
@ -259,15 +261,15 @@ val chop_suffix : suf:string -> string -> string option
|
|||
*)
|
||||
|
||||
val take : int -> string -> string
|
||||
(** [take n s] keeps only the [n] first chars of [s]
|
||||
(** [take n s] keeps only the [n] first chars of [s].
|
||||
@since 0.17 *)
|
||||
|
||||
val drop : int -> string -> string
|
||||
(** [drop n s] removes the [n] first chars of [s]
|
||||
(** [drop n s] removes the [n] first chars of [s].
|
||||
@since 0.17 *)
|
||||
|
||||
val take_drop : int -> string -> string * string
|
||||
(** [take_drop n s = take n s, drop n s]
|
||||
(** [take_drop n s = take n s, drop n s].
|
||||
@since 0.17 *)
|
||||
|
||||
(*$=
|
||||
|
|
@ -277,11 +279,11 @@ val take_drop : int -> string -> string * string
|
|||
*)
|
||||
|
||||
val lines : string -> string list
|
||||
(** [lines s] returns a list of the lines of [s] (splits along '\n')
|
||||
(** [lines s] returns a list of the lines of [s] (splits along '\n').
|
||||
@since 0.10 *)
|
||||
|
||||
val lines_gen : string -> string gen
|
||||
(** [lines_gen s] returns a generator of the lines of [s] (splits along '\n')
|
||||
(** [lines_gen s] returns a generator of the lines of [s] (splits along '\n').
|
||||
@since 0.10 *)
|
||||
|
||||
(*$= & ~printer:Q.Print.(list @@ Printf.sprintf "%S")
|
||||
|
|
@ -297,11 +299,11 @@ val concat_gen : sep:string -> string gen -> string
|
|||
@since 0.10 *)
|
||||
|
||||
val unlines : string list -> string
|
||||
(** [unlines l] concatenates all strings of [l], separated with '\n'
|
||||
(** [unlines l] concatenates all strings of [l], separated with '\n'.
|
||||
@since 0.10 *)
|
||||
|
||||
val unlines_gen : string gen -> string
|
||||
(** [unlines_gen g] concatenates all strings of [g], separated with '\n'
|
||||
(** [unlines_gen g] concatenates all strings of [g], separated with '\n'.
|
||||
@since 0.10 *)
|
||||
|
||||
(*$= & ~printer:CCFun.id
|
||||
|
|
@ -323,7 +325,7 @@ val unlines_gen : string gen -> string
|
|||
val set : string -> int -> char -> string
|
||||
(** [set s i c] creates a new string which is a copy of [s], except
|
||||
for index [i], which becomes [c].
|
||||
@raise Invalid_argument if [i] is an invalid index
|
||||
@raise Invalid_argument if [i] is an invalid index.
|
||||
@since 0.12 *)
|
||||
|
||||
(*$T
|
||||
|
|
@ -333,19 +335,19 @@ val set : string -> int -> char -> string
|
|||
*)
|
||||
|
||||
val iter : (char -> unit) -> string -> unit
|
||||
(** Alias to {!String.iter}
|
||||
(** Alias to {!String.iter}.
|
||||
@since 0.12 *)
|
||||
|
||||
val iteri : (int -> char -> unit) -> string -> unit
|
||||
(** Iter on chars with their index
|
||||
(** Iter on chars with their index.
|
||||
@since 0.12 *)
|
||||
|
||||
val map : (char -> char) -> string -> string
|
||||
(** Map chars
|
||||
(** Map chars.
|
||||
@since 0.12 *)
|
||||
|
||||
val mapi : (int -> char -> char) -> string -> string
|
||||
(** Map chars with their index
|
||||
(** Map chars with their index.
|
||||
@since 0.12 *)
|
||||
|
||||
val filter_map : (char -> char option) -> string -> string
|
||||
|
|
@ -368,8 +370,8 @@ val filter : (char -> bool) -> string -> string
|
|||
*)
|
||||
|
||||
val flat_map : ?sep:string -> (char -> string) -> string -> string
|
||||
(** Map each chars to a string, then concatenates them all
|
||||
@param sep optional separator between each generated string
|
||||
(** Map each chars to a string, then concatenates them all.
|
||||
@param sep optional separator between each generated string.
|
||||
@since 0.12 *)
|
||||
|
||||
val for_all : (char -> bool) -> string -> bool
|
||||
|
|
@ -383,11 +385,11 @@ val exists : (char -> bool) -> string -> bool
|
|||
include S with type t := string
|
||||
|
||||
val ltrim : t -> t
|
||||
(** trim space on the left (see {!String.trim} for more details)
|
||||
(** Trim space on the left (see {!String.trim} for more details).
|
||||
@since 1.2 *)
|
||||
|
||||
val rtrim : t -> t
|
||||
(** trim space on the right (see {!String.trim} for more details)
|
||||
(** Trim space on the right (see {!String.trim} for more details).
|
||||
@since 1.2 *)
|
||||
|
||||
(*$= & ~printer:id
|
||||
|
|
@ -411,39 +413,39 @@ val rtrim : t -> t
|
|||
(** {2 Operations on 2 strings} *)
|
||||
|
||||
val map2 : (char -> char -> char) -> string -> string -> string
|
||||
(** Map pairs of chars
|
||||
@raise Invalid_argument if the strings have not the same length
|
||||
(** Map pairs of chars.
|
||||
@raise Invalid_argument if the strings have not the same length.
|
||||
@since 0.12 *)
|
||||
|
||||
val iter2: (char -> char -> unit) -> string -> string -> unit
|
||||
(** Iterate on pairs of chars
|
||||
@raise Invalid_argument if the strings have not the same length
|
||||
(** Iterate on pairs of chars.
|
||||
@raise Invalid_argument if the strings have not the same length.
|
||||
@since 0.12 *)
|
||||
|
||||
val iteri2: (int -> char -> char -> unit) -> string -> string -> unit
|
||||
(** Iterate on pairs of chars with their index
|
||||
@raise Invalid_argument if the strings have not the same length
|
||||
(** Iterate on pairs of chars with their index.
|
||||
@raise Invalid_argument if the strings have not the same length.
|
||||
@since 0.12 *)
|
||||
|
||||
val fold2: ('a -> char -> char -> 'a) -> 'a -> string -> string -> 'a
|
||||
(** Fold on pairs of chars
|
||||
@raise Invalid_argument if the strings have not the same length
|
||||
(** Fold on pairs of chars.
|
||||
@raise Invalid_argument if the strings have not the same length.
|
||||
@since 0.12 *)
|
||||
|
||||
val for_all2 : (char -> char -> bool) -> string -> string -> bool
|
||||
(** All pairs of chars respect the predicate?
|
||||
@raise Invalid_argument if the strings have not the same length
|
||||
@raise Invalid_argument if the strings have not the same length.
|
||||
@since 0.12 *)
|
||||
|
||||
val exists2 : (char -> char -> bool) -> string -> string -> bool
|
||||
(** Exists a pair of chars?
|
||||
@raise Invalid_argument if the strings have not the same length
|
||||
@raise Invalid_argument if the strings have not the same length.
|
||||
@since 0.12 *)
|
||||
|
||||
(** {2 Ascii functions}
|
||||
|
||||
Those functions are deprecated in {!String} since 4.03, so we provide
|
||||
a stable alias for them even in older versions *)
|
||||
a stable alias for them even in older versions. *)
|
||||
|
||||
val capitalize_ascii : string -> string
|
||||
(** See {!String}. @since 0.18 *)
|
||||
|
|
@ -475,7 +477,7 @@ val equal_caseless : string -> string -> bool
|
|||
|
||||
(** {2 Finding}
|
||||
|
||||
A relatively efficient algorithm for finding sub-strings
|
||||
A relatively efficient algorithm for finding sub-strings.
|
||||
@since 1.0 *)
|
||||
|
||||
module Find : sig
|
||||
|
|
@ -486,14 +488,14 @@ module Find : sig
|
|||
val rcompile : string -> [ `Reverse ] pattern
|
||||
|
||||
val find : ?start:int -> pattern:[`Direct] pattern -> string -> int
|
||||
(** Search for [pattern] in the string, left-to-right
|
||||
@return the offset of the first match, -1 otherwise
|
||||
@param start offset in string at which we start *)
|
||||
(** Search for [pattern] in the string, left-to-right.
|
||||
@return the offset of the first match, -1 otherwise.
|
||||
@param start offset in string at which we start. *)
|
||||
|
||||
val rfind : ?start:int -> pattern:[`Reverse] pattern -> string -> int
|
||||
(** Search for [pattern] in the string, right-to-left
|
||||
@return the offset of the start of the first match from the right, -1 otherwise
|
||||
@param start right-offset in string at which we start *)
|
||||
(** Search for [pattern] in the string, right-to-left.
|
||||
@return the offset of the start of the first match from the right, -1 otherwise.
|
||||
@param start right-offset in string at which we start. *)
|
||||
end
|
||||
|
||||
(** {2 Splitting} *)
|
||||
|
|
@ -501,10 +503,10 @@ end
|
|||
module Split : sig
|
||||
(** Specification of what to do with empty blocks, as in [split ~by:"-" "-a-b-"].
|
||||
|
||||
- [{first=false; last=false}] will return [""; "a"; "b"; ""]
|
||||
- [{first=true; last=false}] will return ["a"; "b" ""]
|
||||
- [{first=false; last=true}] will return [""; "a"; "b"]
|
||||
- [{first=true; last=true}] will return ["a"; "b"]
|
||||
- [{first=false; last=false}] will return [""; "a"; "b"; ""].
|
||||
- [{first=true; last=false}] will return ["a"; "b" ""].
|
||||
- [{first=false; last=true}] will return [""; "a"; "b"].
|
||||
- [{first=true; last=true}] will return ["a"; "b"].
|
||||
|
||||
The default value of all remaining functions is [Drop_none].
|
||||
@since 1.5
|
||||
|
|
@ -515,17 +517,17 @@ module Split : sig
|
|||
}
|
||||
|
||||
val no_drop : drop_if_empty
|
||||
(** Do not drop any group, even empty and on borders
|
||||
(** Do not drop any group, even empty and on borders.
|
||||
@since 1.5 *)
|
||||
|
||||
val list_ : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) list
|
||||
(** Eplit the given string along the given separator [by]. Should only
|
||||
(** Split the given string along the given separator [by]. Should only
|
||||
be used with very small separators, otherwise
|
||||
use {!Containers_string.KMP}.
|
||||
@return a list of slices [(s,index,length)] that are
|
||||
separated by [by]. {!String.sub} can then be used to actually extract
|
||||
a string from the slice.
|
||||
@raise Failure if [by = ""] *)
|
||||
@raise Failure if [by = ""]. *)
|
||||
|
||||
val gen : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) gen
|
||||
|
||||
|
|
@ -536,7 +538,7 @@ module Split : sig
|
|||
(** {6 Copying functions}
|
||||
|
||||
Those split functions actually copy the substrings, which can be
|
||||
more convenient but less efficient in general *)
|
||||
more convenient but less efficient in general. *)
|
||||
|
||||
val list_cpy : ?drop:drop_if_empty -> by:string -> string -> string list
|
||||
|
||||
|
|
@ -554,12 +556,12 @@ module Split : sig
|
|||
|
||||
val left : by:string -> string -> (string * string) option
|
||||
(** Split on the first occurrence of [by] from the leftmost part of
|
||||
the string
|
||||
the string.
|
||||
@since 0.12 *)
|
||||
|
||||
val left_exn : by:string -> string -> string * string
|
||||
(** Split on the first occurrence of [by] from the leftmost part of the string
|
||||
@raise Not_found if [by] is not part of the string
|
||||
(** Split on the first occurrence of [by] from the leftmost part of the string.
|
||||
@raise Not_found if [by] is not part of the string.
|
||||
@since 0.16 *)
|
||||
|
||||
(*$T
|
||||
|
|
@ -572,12 +574,12 @@ module Split : sig
|
|||
|
||||
val right : by:string -> string -> (string * string) option
|
||||
(** Split on the first occurrence of [by] from the rightmost part of
|
||||
the string
|
||||
the string.
|
||||
@since 0.12 *)
|
||||
|
||||
val right_exn : by:string -> string -> string * string
|
||||
(** Split on the first occurrence of [by] from the rightmost part of the string
|
||||
@raise Not_found if [by] is not part of the string
|
||||
(** Split on the first occurrence of [by] from the rightmost part of the string.
|
||||
@raise Not_found if [by] is not part of the string.
|
||||
@since 0.16 *)
|
||||
|
||||
(*$T
|
||||
|
|
@ -589,7 +591,7 @@ module Split : sig
|
|||
end
|
||||
|
||||
val split_on_char : char -> string -> string list
|
||||
(** Split the string along the given char
|
||||
(** Split the string along the given char.
|
||||
@since 1.2 *)
|
||||
|
||||
(*$= & ~printer:Q.Print.(list string)
|
||||
|
|
@ -604,7 +606,7 @@ val split_on_char : char -> string -> string list
|
|||
*)
|
||||
|
||||
val split : by:string -> string -> string list
|
||||
(** Alias to {!Split.list_cpy}
|
||||
(** Alias to {!Split.list_cpy}.
|
||||
@since 1.2 *)
|
||||
|
||||
(** {2 Utils} *)
|
||||
|
|
@ -655,7 +657,7 @@ val compare_natural : string -> string -> int
|
|||
val edit_distance : string -> string -> int
|
||||
(** Edition distance between two strings. This satisfies the classical
|
||||
distance axioms: it is always positive, symmetric, and satisfies
|
||||
the formula [distance a b + distance b c >= distance a c] *)
|
||||
the formula [distance a b + distance b c >= distance a c]. *)
|
||||
|
||||
(*$Q
|
||||
Q.(string_of_size Gen.(0 -- 30)) (fun s -> \
|
||||
|
|
@ -666,7 +668,7 @@ val edit_distance : string -> string -> int
|
|||
a string s' that is accepted by a.
|
||||
|
||||
--> generate triples (s, i, c) where c is a char, s a non empty string
|
||||
and i a valid index in s
|
||||
and i a valid index in s.
|
||||
*)
|
||||
|
||||
(*$QR
|
||||
|
|
@ -690,24 +692,24 @@ val edit_distance : string -> string -> int
|
|||
|
||||
module Sub : sig
|
||||
type t = string * int * int
|
||||
(** A string, an offset, and the length of the slice *)
|
||||
(** A string, an offset, and the length of the slice. *)
|
||||
|
||||
val make : string -> int -> len:int -> t
|
||||
|
||||
val full : string -> t
|
||||
(** Full string *)
|
||||
(** Full string. *)
|
||||
|
||||
val copy : t -> string
|
||||
(** Make a copy of the substring *)
|
||||
(** Make a copy of the substring. *)
|
||||
|
||||
val underlying : t -> string
|
||||
|
||||
val sub : t -> int -> int -> t
|
||||
(** Sub-slice *)
|
||||
(** Sub-slice. *)
|
||||
|
||||
val get : t -> int -> char
|
||||
(** [get s i] gets the [i]-th element, or fails
|
||||
@raise Invalid_argument if the index is not within [0... length -1]
|
||||
(** [get s i] gets the [i]-th element, or fails.
|
||||
@raise Invalid_argument if the index is not within [0 ... length - 1].
|
||||
@since 1.2 *)
|
||||
|
||||
include S with type t := t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue