package octez-proto-libs

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include Array end
type 'a t = 'a array

An alias for the type of arrays.

val length : 'a array -> int

Return the length (number of elements) of the given array.

val init : int -> (int -> 'a) -> 'a 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.

  • raises Invalid_argument

    if n < 0 or n > Sys.max_array_length. If the return type of f is float, then the maximum size is only Sys.max_array_length / 2.

val create_matrix : int -> int -> 'a -> 'a array array
val append : 'a array -> 'a array -> 'a array

append v1 v2 returns a fresh array containing the concatenation of the arrays v1 and v2.

val concat : 'a array list -> 'a array

Same as append, but concatenates a list of arrays.

val copy : 'a array -> 'a array

copy a returns a copy of a, that is, a fresh array containing the same elements as a.

val to_list : 'a array -> 'a list

to_list a returns the list of all the elements of a.

val of_list : 'a list -> 'a array

of_list l returns a fresh array containing the elements of l.

  • raises Invalid_argument

    if the length of l is greater than Sys.max_array_length.

Iterators

val iter : ('a -> unit) -> 'a array -> unit

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); ().

val iteri : (int -> 'a -> unit) -> 'a array -> unit

Same as iter, but the function is applied to the index of the element as first argument, and the element itself as second argument.

val map : ('a -> 'b) -> 'a array -> 'b array

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) |].

val mapi : (int -> 'a -> 'b) -> 'a array -> 'b array

Same as map, but the function is applied to the index of the element as first argument, and the element itself as second argument.

val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a

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.

val fold_left_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b array -> 'a * 'c array

fold_left_map is a combination of fold_left and map that threads an accumulator through calls to f.

  • since 4.13.0
val fold_right : ('b -> 'a -> 'a) -> 'b array -> 'a -> '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

val for_all : ('a -> bool) -> 'a array -> bool

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).

  • since 4.03.0
val exists : ('a -> bool) -> 'a array -> bool

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).

  • since 4.03.0
val for_all2 : ('a -> 'b -> bool) -> 'a array -> 'b array -> bool

Same as for_all, but for a two-argument predicate.

  • since 4.11.0
val exists2 : ('a -> 'b -> bool) -> 'a array -> 'b array -> bool

Same as exists, but for a two-argument predicate.

  • since 4.11.0
val mem : 'a -> 'a array -> bool

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).

  • since 4.03.0
val memq : 'a -> 'a array -> bool

Same as mem, but uses physical equality instead of structural equality to compare list elements.

  • since 4.03.0
val find_opt : ('a -> bool) -> 'a array -> 'a option

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.

  • since 4.13.0
val find_map : ('a -> 'b option) -> 'a array -> 'b option

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.

  • since 4.13.0

Arrays of pairs

val split : ('a * 'b) array -> 'a array * 'b array

split [|(a1,b1); ...; (an,bn)|] is ([|a1; ...; an|], [|b1; ...; bn|]).

  • since 4.13.0

Sorting

Arrays and Sequences

val of_seq : 'a Seq.t -> 'a array

Create an array from the generator

  • since 4.07
val get : [> `You_cannot_access_array_content_in_the_protocol ]
val unsafe_get : [> `You_cannot_access_array_content_in_the_protocol ]
val set : [> `You_cannot_modify_array_content_in_the_protocol ]
val unsafe_set : [> `You_cannot_modify_array_content_in_the_protocol ]
val to_seq : [> `You_cannot_traverse_arrays_lazily_in_the_protocol ]
val to_seqi : [> `You_cannot_traverse_arrays_lazily_in_the_protocol ]
val make : [> `You_cannot_build_arrays_with_implicit_sharing_in_the_protocol ]
val create : [> `You_cannot_build_arrays_with_implicit_sharing_in_the_protocol ]
val make_matrix : [> `You_cannot_build_arrays_with_implicit_sharing_in_the_protocol ]
val create_float : [> `You_cannot_use_floats_in_the_protocol ]
val make_float : [> `You_cannot_use_floats_in_the_protocol ]
val sub : [> `You_cannot_cut_arrays_in_the_protocol ]
val fill : [> `You_cannot_fill_arrays_in_the_protocol ]
val blit : [> `You_cannot_blit_arrays_in_the_protocol ]
val iter2 : [> `You_cannot_traverse_2_arrays_at_once_in_the_protocol ]
val map2 : [> `You_cannot_traverse_2_arrays_at_once_in_the_protocol ]
val combine : [> `You_cannot_traverse_2_arrays_at_once_in_the_protocol ]
val sort : [> `You_cannot_sort_arrays_in_the_protocol ]
val stable_sort : [> `You_cannot_sort_arrays_in_the_protocol ]
val fast_sort : [> `You_cannot_sort_arrays_in_the_protocol ]
module Floatarray : sig ... end
OCaml

Innovation. Community. Security.