Module Prime_array
Amendment to the standard library Array
structure.
val sample : (int -> 'a) -> int -> 'a array
sample f n
returns[|f 0; …; f (n - 1)|]
. This callsinit
with arguments reversed.
val filter : ('a -> bool) -> 'a array -> 'a array
filter f xa
is the array containing the elements ofxa
on whichf
is true with order preserved.
val fmap : ('a -> 'b option) -> 'a array -> 'b array
val filter_map : ('a -> 'b option) -> 'a array -> 'b array
filter_map f xa
is the array of the non-None
elements ofmap f xa
, preserving order.
val foldi : (int -> 'a -> 'b -> 'b) -> 'a array -> 'b -> 'b
foldi f [|x₁; …; xₙ|]
isf (n - 1) xₙ ∘ ⋯ ∘ f 0 x₁
.
val for_all : ('a -> bool) -> 'a array -> bool
for_all f [|x₁; …; xₙ|]
is true ifff xᵢ
is true for alli
.f
is applied to the elements in order until false is returned.
val exists : ('a -> bool) -> 'a array -> bool
exists f [|x₁; …; xₙ|]
is true ifff xᵢ
is true for somei
.f
is applied to the elements in order until true is returned.
val count : ('a -> bool) -> 'a array -> int
count f xa
is the number of elementsx
ofxa
for whichf x
holds.