This module implements an iterator for array slices (Subarray).
Equations
Instances For
Equations
Equations
Equations
Without defining the following function Subarray.foldlM, it is still possible to call
subarray.foldlM, which would be elaborated to Slice.foldlM (s := subarray). However, in order to
maximize backward compatibility and avoid confusion in the manual entry for Subarray, we
explicitly provide the wrapper function Subarray.foldlM for Slice.foldlM, providing a more
specific docstring.
Folds a monadic operation from left to right over the elements in a subarray.
An accumulator of type β is constructed by starting with init and monadically combining each
element of the subarray with the current accumulator value in turn. The monad in question may permit
early termination or repetition.
Examples:
#eval #["red", "green", "blue"].toSubarray.foldlM (init := "") fun acc x => do
let l ← Option.guard (· ≠ 0) x.length
return s!"{acc}({l}){x} "
some "(3)red (5)green (4)blue "
#eval #["red", "green", "blue"].toSubarray.foldlM (init := 0) fun acc x => do
let l ← Option.guard (· ≠ 5) x.length
return s!"{acc}({l}){x} "
none
Equations
Instances For
Folds an operation from left to right over the elements in a subarray.
An accumulator of type β is constructed by starting with init and combining each
element of the subarray with the current accumulator value in turn.
Examples:
#["red", "green", "blue"].toSubarray.foldl (· + ·.length) 0 = 12#["red", "green", "blue"].toSubarray.popFront.foldl (· + ·.length) 0 = 9
Equations
Instances For
Allocates a new array that contains the contents of the subarray.
Equations
Instances For
Allocates a new array that contains the contents of the subarray.
Equations
Instances For
Allocates a new array that contains the contents of the subarray.