package octez-libs

  1. Overview
  2. Docs
A package that contains multiple base libraries used by the Octez suite

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65

doc/octez-libs.stdlib/Tezos_stdlib/FallbackArray/index.html

Module Tezos_stdlib.FallbackArraySource

This module implements arrays equipped with accessors that cannot raise exceptions. Reading out of the bounds of the arrays return a fallback value fixed at array construction time, writing out of the bounds of the arrays is ignored.

Sourcetype 'a t

The type for array containing values of type 'a.

Sourceval make : int -> 'a -> 'a t

make len v builds an array a initialized len cells with v. The value v is the fallback value for a.

Sourceval of_list : fallback:'b -> proj:('a -> 'b) -> 'a list -> 'b t

of_list ~fallback ~proj l builds a fallback array a of length List.length l where each cell i is initialized by proj (List.nth l i) and the fallback value is fallback.

Sourceval fallback : 'a t -> 'a

fallback a returns the fallback value for a.

Sourceval length : 'a t -> int

length a returns the length of a.

Sourceval get : 'a t -> int -> 'a

get a idx returns the contents of the cell of index idx in a. If idx < 0 or idx >= length a, get a idx = fallback a.

Sourceval set : 'a t -> int -> 'a -> unit

set a idx value updates the cell of index idx with value. If idx < 0 or idx >= length a, a is unchanged.

Sourceval iter : ('a -> unit) -> 'a t -> unit

iter f a iterates f over the cells of a from the cell indexed 0 to the cell indexed length a - 1.

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

map f a computes a new array obtained by applying f to each cell contents of a. Notice that the fallback value of the new array is f (fallback a).

Sourceval fold : ('b -> 'a -> 'b) -> 'a t -> 'b -> 'b

fold f a init traverses a from the cell indexed 0 to the cell indexed length a - 1 and transforms accu into f accu x where x is the content of the cell under focus. accu is init on the first iteration.

Sourceval fold_map : ('b -> 'a -> 'b * 'c) -> 'a t -> 'b -> 'c -> 'b * 'c t

fold_map f a init fallback traverses a from the cell indexed 0 to the cell indexed length a - 1 and transforms accu into fst (f accu x) where x is the content of the cell under focus. accu is init on the first iteration. The function also returns a fresh array containing snd (f accu x) for each x. fallback is required to initialize a fresh array before it can be filled.

OCaml

Innovation. Community. Security.