chunk_e n e splits enum e into chunks of n elements each (except the last which can be shorter). NB the order in result is not specified
List utilities
val list_min : ?cmp:('a->'a-> int)->'a list->'a
find the minimum element in the list
parametercmp
compare function, default Stdlib.compare
raisesEmpty_list
when list is empty
val list_uniq : ('a->'b)->'a list->'a list
list_uniq f l
returns
copy of l that will not contain two values x and x' such that f x = f x'.
val list_sorted_uniq : ('a->'a-> bool)->'a list->'a list
list_sorted_uniq eq_f l
returns
l without consecutive elements x, x' such that eq_f
x = eq_f x'.
val list_random_exn : ?state:Stdlib.Random.State.t ->'a list->'a
Get a random element from a list.
val list_random : ?state:Stdlib.Random.State.t ->'a list->'a option
val slice : int ->int ->'a list->'a list
extract sublist from a list, e.g. slice 1 3 [0;1;2;3;4] will return [1;2;3].
Partitioning a list into chunks
val chunk : int ->'a list->'a list list
chunk n l splits list l into chunks of n elements each (except the last which can be shorter). NB the order in result is not specified FIXME?
val distribute : int ->'a list->'a list array
distribute n l splits l into n chunks, does not preserve the order of the elements.
val undistribute : 'a list array->'a list
val partition : int ->'a list->'a list array
deprecated use Action.distribute
val unpartition : 'a list array->'a list
deprecated use Action.undistribute
val stable_partition : int ->'a list->'a list list
stable_partition l n splits l into n chunks, preserves the order of the elements.
val stable_unpartition : 'a list list->'a list
Array utilities
val array_random_exn : ?state:Stdlib.Random.State.t ->'a array->'a
val array_random : ?state:Stdlib.Random.State.t ->'a array->'a option
val array_rfindi : ('a-> bool)->'a array-> int
array_rfindi p a
returns
index of first element matching p when iterating a in reverse.
raisesNot_found
if no such element exists.
val array_rfind : ('a-> bool)->'a array->'a
array_rfind p a
returns
value index of first element matching p when iterating a in reverse.
raisesNot_found
if no such element exists.
val array_iter_rev : ('a-> unit)->'a array-> unit
array_iter_rev f a calls f on each elements of a in reverse order.
val shuffle : ?state:Stdlib.Random.State.t ->'a array-> unit
shuffle ?state a shuffles an array, giving a uniform random distribution.
parameterstate
random state to use (default: global Random state)
val binary_search' : 'a array->('a->'b-> int)->'b->'a option
array must be sorted
val binary_search : 'a array->('a->'b-> int)->'b-> bool
val chunk_a : int ->'a array->'a array list
chunk_a n a splits array a into chunks of n elements each (except the last which can be shorter), preserving the order of elements, i.e. reverse operation is Array.concat
DynArray utilities
val quick_sort :
'aDynArray.t->?start:int ->?n:int ->('a->'a-> int)->
unit
Hashtbl utilities
val hashtbl_find : ('a, 'b)Stdlib.Hashtbl.t->(unit ->'b)->'a->'b
hashtbl_find ht f_default k associates f_default () to k in ht, if no previous association exists.
returns
Hashtbl.find ht k if k is associated with an element in ht, or f_default () otherwise.
Basic timer. Also allows recording a sequence of interesting times from the given start point. Can serialize recorded events to json (useful for Logstash events)