partition_tf t ~f returns a pair t1, t2, where t1 is all elements of t that satisfy f, and t2 is all elements of t that do not satisfy f. The "tf" suffix is mnemonic to remind readers that the result is (trues, falses).
val partition_map : 'at->f:('a->('b, 'c)Base__.Either0.t)->'bt * 'ct
val fold : 'at->init:'acc->f:('acc->'a->'acc)->'acc
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:'acc->f:('acc->'a->('acc, 'e)Result.t)->('acc, '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:'acc->f:('acc->'a->('acc, 'final)Container.Continue_or_stop.t)->finish:('acc->'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
These are all like their equivalents in Container except that an index starting at 0 is added as the first argument to f.
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).
create_local ~len x is like create. It allocates the array on the local stack. The array's elements are still global.
val create_float_uninitialized : len:int ->float t
create_float_uninitialized ~len creates a float array of length len with uninitialized elements -- that is, they may contain arbitrary, nondeterministic float values. This can be significantly faster than using create, when unboxed float array representations are enabled.
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.
Merges two arrays: assuming that a1 and a2 are sorted according to the comparison function compare, merge a1 a2 ~compare will return a sorted array containing all the elements of a1 and a2. If several elements compare equal, the elements of a1 will be before the elements of a2.
val partitioni_tf : 'at->f:(int ->'a-> bool)->'at * 'at
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.
Functions with the 2 suffix raise an exception if the lengths of the two given arrays aren't the same.
val iter2_exn : 'at->'bt->f:('a->'b-> unit)-> unit
Returns the first evaluation of f that returns Some. Raises Stdlib.Not_found or Not_found_s if f always returns None.
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 Stdlib.Not_found or Not_found_s if there is no such element.
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.