val fold : 'at->init:'accum->f:('accum->'a->'accum)->'accum
fold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en are the elements of t
val fold_result :
'at->init:'accum->f:('accum->'a->('accum, 'e)Result.t)->('accum, 'e)Result.t
fold_result t ~init ~f is a short-circuiting version of fold that runs in the Result monad. If f returns an Error _, that value is returned without any additional invocations of f.
val fold_until :
'at->init:'accum->f:('accum->'a->('accum, 'final)Base__.Container_intf.Continue_or_stop.t)->finish:('accum->'final)->'final
fold_until t ~init ~f ~finish is a short-circuiting version of fold. If f returns Stop _ the computation ceases and results in that value. If f returns Continue _, the fold will proceed. If f never returns Stop _, the final result is computed by finish.
Example:
type maybe_negative =
| Found_negative of int
| All_nonnegative of { sum : int }
(** [first_neg_or_sum list] returns the first negative number in [list], if any,
otherwise returns the sum of the list. *)
let first_neg_or_sum =
List.fold_until ~init:0
~f:(fun sum x ->
if x < 0
then Stop (Found_negative x)
else Continue (sum + x))
~finish:(fun sum -> All_nonnegative { sum })
;;
let x = first_neg_or_sum [1; 2; 3; 4; 5]
val x : maybe_negative = All_nonnegative {sum = 15}
let y = first_neg_or_sum [1; 2; -3; 4; 5]
val y : maybe_negative = Found_negative -3
val min_elt : 'at->compare:('a->'a-> int)->'a option
Returns a minimum (resp maximum) element from the collection using the provided compare function, or None if the collection is empty. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold so it has the same complexity as fold.
val max_elt : 'at->compare:('a->'a-> int)->'a option
Array.get a n returns the element number n of array a. The first element has number 0. The last element has number Array.length a - 1. You can also write a.(n) instead of Array.get a n.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to (Array.length a - 1).
Array.make_matrix dimx dimy e returns a two-dimensional array (an array of arrays) with first dimension dimx and second dimension dimy. All the elements of this new matrix are initially physically equal to e. The element (x,y) of a matrix m is accessed with the notation m.(x).(y).
Raise Invalid_argument if dimx or dimy is negative or greater than Array.max_length.
If the value of e is a floating-point number, then the maximum size is only Array.max_length / 2.
Array.fill a ofs len x modifies the array a in place, storing x in elements number ofs to ofs + len - 1.
Raise Invalid_argument "Array.fill" if ofs and len do not designate a valid subarray of a.
Array.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.
int_blit and float_blit provide fast bound-checked blits for immediate data types. The unsafe versions do not bound-check the arguments.
Array.map t ~f applies function f to all the elements of t, and builds an array with the results returned by f: [| f t.(0); f t.(1); ...; f t.(Array.length t - 1)
|].
val folding_map : 'at->init:'b->f:('b->'a->'b * 'c)->'ct
folding_map is a version of map that threads an accumulator through calls to f.
val folding_mapi : 'at->init:'b->f:(int ->'b->'a->'b * 'c)->'ct
val fold_map : 'at->init:'b->f:('b->'a->'b * 'c)->'b * 'ct
Array.fold_map is a combination of Array.fold and Array.map that threads an accumulator through calls to f.
val fold_mapi : 'at->init:'b->f:(int ->'b->'a->'b * 'c)->'b * 'ct
filter_opt array returns a new array where None entries are omitted and Some x entries are replaced with x. Note that this changes the index at which elements will appear.
Returns the first evaluation of f that returns Some. Raises Caml.Not_found or Not_found_s if f always returns None.
val findi : 'at->f:(int ->'a-> bool)->(int * 'a) option
findi t f returns the first index i of t for which f i t.(i) is true
val findi_exn : 'at->f:(int ->'a-> bool)-> int * 'a
findi_exn t f returns the first index i of t for which f i t.(i) is true. It raises Caml.Not_found or Not_found_s if there is no such element.
val find_mapi : 'at->f:(int ->'a->'b option)->'b option
find_mapi t f is like find_map but passes the index as an argument.
val find_mapi_exn : 'at->f:(int ->'a->'b option)->'b
find_mapi_exn is like find_map_exn but passes the index as an argument.
val find_consecutive_duplicate :
'at->equal:('a->'a-> bool)->('a * 'a) option
find_consecutive_duplicate t ~equal returns the first pair of consecutive elements (a1, a2) in t such that equal a1 a2. They are returned in the same order as they appear in t.