Checks whether the provided element is there, using polymorphic compare if equal
is not provided
fold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en
are the elements of t
Returns true if and only if there exists an element for which the provided
function evaluates to true. This is a short-circuiting operation.
Returns true if and only if the provided function evaluates to true for all
elements. This is a short-circuiting operation.
Returns the number of elements for which the provided function evaluates to true.
Returns as an option the first element for which f evaluates to true.
Returns the first evaluation of f that returns Some, and returns None if there
is no such element.
Returns a minimum (resp maximum) element from the collection using the provided
cmp 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.
Maximum length of a normal array. The maximum length of a float array is
max_length/2 on 32-bit machines and max_length on 64-bit machines.
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.set a n x modifies array a in place, replacing
element number n with x.
You can also write a.(n) <- x instead of Array.set a n x.
Raise Invalid_argument "index out of bounds"
if n is outside the range 0 to Array.length a - 1.
Unsafe version of get. Can cause arbitrary behavior when used for an out-of-bounds
array access
Unsafe version of set. Can cause arbitrary behavior when used for an out-of-bounds
array access
create ~len x creates an array of length len with the value x populated in
each element
init n ~f creates an array of length n where the ith element is initialized
with f i (starting at zero)
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 Sys.max_array_length.
If the value of e is a floating-point number, then the maximum
size is only Sys.max_array_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.of_list l returns a fresh array containing the elements of l.
Like Array.iter, but the function is applied to the index of the element as first argument, and the element itself as second argument.
Array.fold_right f a ~init computes
f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...)),
where n is the length of the array a.
All sort functions in this module sort in increasing order by default.
sort uses constant heap space. stable_sort uses linear heap space.
To sort only part of the array, specify pos to be the index to start sorting from
and len indicating how many elements to sort.
is_sorted_strictly xs ~cmp iff is_sorted xs ~cmp and no two consecutive elements
in xs are equal according to cmp
Like List.concat_map, List.concat_mapi.
normalize array index returns a new index into the array such that if index is
less than zero, the returned index will "wrap around" -- i.e. array.(normalize array
(-1)) returns the last element of the array.
slice array start stop returns a fresh array including elements array.(start)
through array.(stop-1) with the small tweak that the start and stop positions are
normalized and a stop index of 0 means the same thing a stop index of Array.length
array. In summary, it's mostly like the slicing in Python or Matlab. One
difference is that a stop value of 0 here is like not specifying a stop value in
Python.
Array access with normalized index.
Array modification with normalized index.
Like for_all, but passes the index as an argument.
Like exists, but passes the index as an argument.
Like count, but passes the index as an argument.
swap arr i j swaps the value at index i with that at index j.
rev_inplace t reverses t in place
of_list_rev l converts from list then reverses in place
of_list_map l ~f is the same as of_list (List.map l ~f)
of_list_rev_map l ~f is the same as rev_inplace (of_list_map l ~f)
replace t i ~f = t.(i) <- f (t.(i)).
modifies an array in place -- ar.(i) will be set to f(ar.(i))
find_exn f t returns the first a in t for which f t.(i) is true.
It raises Not_found if there is no such a.
Returns the first evaluation of f that returns Some.
Raises Not_found if f always returns None.
findi t f returns the first index i of t for which f i t.(i) is true
findi_exn t f returns the first index i of t for which f i t.(i) is
true. It raises Not_found if there is no such element.
find_mapi t f is the like find_map but passes the index as an argument.
find_mapi_exn is the like find_map_exn but passes the index as an argument.
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.
reduce f [a1; ...; an] is Some (f (... (f (f a1 a2) a3) ...) an).
Returns None on the empty array.
permute ?random_state t randomly permutes t in place.
permute side affects random_state by repeated calls to Random.State.int.
If random_state is not supplied, permute uses Random.State.default.
empty () creates an empty array
truncate t ~len drops length t - len elements from the end of t, changing t
so that length t = len afterwards. truncate raises if len <= 0 || len > length
t.
to_sequence t converts t to a sequence. t is copied internally so that future
modifications of t do not change the sequence.
to_sequence_mutable t converts t to a sequence. t is shared with the sequence
and modifications of t will result in modification of the sequence.
Permissioned module gives the ability to restrict permissions on an array, so
you can give a function read-only access to an array, create an immutable array, etc.