package tezos-protocol-environment
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ad9e08819871c75ba6f4530b125f7d157799398e4d77a1e6bfea9d91ff37ff55
sha512=c5dc4d40cc09bc6980fbbdb5c2e105bf4252cf9cfcb2b49660b0ebe4dc789f6709ec3b3bf2f87d81580d3eed9521eeb1c960f24d9b14eb0285aaba1f84d10a9b
doc/tezos-protocol-environment.structs/Tezos_protocol_environment_structs/V7/Array/index.html
Module V7.Array
Source
include module type of struct include Array end
An alias for the type of arrays.
Return the length (number of elements) of the given array.
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
.
copy a
returns a copy of a
, that is, a fresh array containing the same elements as a
.
to_list a
returns the list of all the elements of a
.
of_list l
returns a fresh array containing the elements of l
.
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|])
.