This module provides slice notation for array slices (a.k.a. Subarray
) and implements an iterator
for those slices.
Equations
- One or more equations did not get rendered due to their size.
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
- Subarray.foldlM f init as = Std.Slice.foldlM f init as
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
- Subarray.foldl f init as = Std.Slice.foldl f init as
Instances For
The implementation of ForIn.forIn
for Subarray
, which allows it to be used with for
loops in
do
-notation.
Instances For
Allocates a new array that contains the contents of the subarray.
Equations
- ↑s = Std.Slice.toArray s
Instances For
Equations
- Array.instCoeSubarray = { coe := Array.ofSubarray }
Equations
- Array.instAppendSubarray = { append := fun (x y : Subarray α) => have a := Std.Slice.toArray x ++ Std.Slice.toArray y; a.toSubarray }
Subarray
representation.
Equations
- Array.Subarray.repr s = repr (Std.Slice.toArray s) ++ Std.Format.text ".toSubarray"
Instances For
Equations
- Array.instReprSubarray = { reprPrec := fun (s : Subarray α) (x : Nat) => Array.Subarray.repr s }
Equations
- Array.instToStringSubarray = { toString := fun (s : Subarray α) => toString (Std.Slice.toArray s) }