package octez-proto-libs
include module type of struct include Array end
init n f
returns a fresh array of length n
, with element number i
initialized to the result of f i
. In other terms, init n f
tabulates the results of f
applied to the integers 0
to n-1
.
append v1 v2
returns a fresh array containing the concatenation of the arrays v1
and v2
.
Same as append
, but concatenates a list of arrays.
copy a
returns a copy of a
, that is, a fresh array containing the same elements as a
.
Iterators
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); ()
.
Same as iter
, but the function is applied to the index of the element as first argument, and the element itself as second argument.
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) |]
.
Same as map
, but the function is applied to the index of the element as first argument, and the element itself as second argument.
fold_left f init a
computes f (... (f (f init a.(0)) a.(1)) ...) a.(n-1)
, where n
is the length of the array a
.
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
.
Iterators on two arrays
Array scanning
for_all f [|a1; ...; an|]
checks if all elements of the array satisfy the predicate f
. That is, it returns (f a1) && (f a2) && ... && (f an)
.
exists f [|a1; ...; an|]
checks if at least one element of the array satisfies the predicate f
. That is, it returns (f a1) || (f a2) || ... || (f an)
.
Same as for_all
, but for a two-argument predicate.
Same as exists
, but for a two-argument predicate.
mem a set
is true if and only if a
is structurally equal to an element of l
(i.e. there is an x
in l
such that compare a x = 0
).
Same as mem
, but uses physical equality instead of structural equality to compare list elements.
find_opt f a
returns the first element of the array a
that satisfies the predicate f
, or None
if there is no value that satisfies f
in the array a
.
find_map f a
applies f
to the elements of a
in order, and returns the first result of the form Some v
, or None
if none exist.
Arrays of pairs
split [|(a1,b1); ...; (an,bn)|]
is ([|a1; ...; an|], [|b1; ...; bn|])
.
Sorting
Arrays and Sequences
val of_seq : 'a Seq.t -> 'a array
Create an array from the generator
module Floatarray : sig ... end