Legend:
Library
Module
Module type
Parameter
Class
Class type
This module implements functional arrays equipped with accessors that cannot raise exceptions following the same design principles as FallbackArray:
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.
Contrary to FallbackArray, writing generates a fresh array.
Please notice that this implementation is naive and should only be used for small arrays. If there is a need for large functional arrays, it is recommended to implement Backer's trick to get constant-time reads and writes for sequences of mutations applied to the same array.
mapi f a computes a new array obtained by applying f to each cell contents of a passing the index of this cell to i. Notice that the fallback value of the new array is f (-1) (fallback a).
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.
val fold_map : ('b->'a->'b * 'c)->'at->'b->'c->'b * 'ct
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.