Equations
- Std.Slice.instToIteratorMk = { State := Std.Iterators.ToIterator.State x m, iterMInternal := Std.Iterators.ToIterator.iterMInternal }
Internal function to obtain an iterator from a slice. Users should import Std.Data.Iterators
and use Std.Slice.iter instead.
Equations
Instances For
This type class provides support for the Slice.size function.
Computes the slice of a
Slice. UseSlice.sizeinstead.
Instances
This type class states that the slice's iterator emits exactly Slice.size elements before
terminating.
- finite (s : Slice α) : Iterators.Finite (Iterators.ToIterator.State s Id) Id
The iterator for every
Slice αis finite. The iterator of a slice
sof typeSlice αemits exactlySliceSize.size selements.
Instances
Returns the number of elements with distinct indices in the given slice.
Example: #[1, 1, 1][0...2].size = 2.
Equations
Instances For
Allocates a new array that contains the elements of the slice.
Equations
Instances For
Allocates a new list that contains the elements of the slice.
Equations
- s.toList = (Std.Slice.Internal.iter s).toList
Instances For
Allocates a new list that contains the elements of the slice in reverse order.
Equations
Instances For
Folds a monadic operation from left to right over the elements in a slice.
An accumulator of type β is constructed by starting with init and monadically combining each
element of the slice with the current accumulator value in turn. The monad in question may permit
early termination or repetition.
Examples for the special case of subarrays:
#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
- Std.Slice.foldlM f init s = Std.Iterators.Iter.foldM f init (Std.Slice.Internal.iter s)
Instances For
Folds an operation from left to right over the elements in a slice.
An accumulator of type β is constructed by starting with init and combining each
element of the slice with the current accumulator value in turn.
Examples for the special case of subarrays:
#["red", "green", "blue"].toSubarray.foldl (· + ·.length) 0 = 12#["red", "green", "blue"].toSubarray.popFront.foldl (· + ·.length) 0 = 9
Equations
- Std.Slice.foldl f init s = Std.Iterators.Iter.fold f init (Std.Slice.Internal.iter s)