If possible, takes n steps with the iterator it and
returns the n-th emitted value, or none if it finished
before emitting n values.
If the iterator is not productive, this function might run forever in an endless loop of iterator
steps. The variant it.ensureTermination.atIdxSlow? is guaranteed to terminate after finitely many
steps.
Equations
- One or more equations did not get rendered due to their size.
Instances For
An induction principle for Iter.atIdxSlow?.
This lemma provides a functional induction principle for reasoning about Iter.atIdxSlow? n it.
The induction follows the structure of iterator steps.
- base case: when we reach the desired index (
n = 0) and get a.yieldstep - inductive case: when we have a
.yieldstep but need to continue (n > 0) - skip case: when we encounter a
.skipstep and continue with the same index - done case: when the iterator is exhausted and we return
none
If possible, takes n steps with the iterator it and
returns the n-th emitted value, or none if it finished
before emitting n values.
This variant terminates after finitely many steps and requires a proof that the iterator is
productive. If such a proof is not available, consider using Iter.toArray.
Equations
- Std.Iter.Total.atIdxSlow? n it = Std.Iter.atIdxSlow? n it.it
Instances For
If possible, takes n steps with the iterator it and
returns the n-th emitted value, or none if it finished
before emitting n values.
If the iterator is not productive, this function might run forever in an endless loop of iterator
steps. The variant it.ensureTermination.atIdxSlow? is guaranteed to terminate after finitely many
steps.
Equations
- Std.Iter.Partial.atIdxSlow? n it = Std.Iter.atIdxSlow? n it.it
Instances For
Returns the n-th value emitted by it, or none if it terminates earlier.
For monadic iterators, the monadic effects of this operation may differ from manually iterating
to the n-th value because atIdx? can take shortcuts. By the signature, the return value
is guaranteed to plausible in the sense of IterM.IsPlausibleNthOutputStep.
This function is only available for iterators that explicitly support it by implementing
the IteratorAccess typeclass.
Equations
- Std.Iter.atIdx? n it = match (Std.IteratorAccess.nextAtIdx? it.toIterM n).run.val with | Std.IterStep.yield it out => some out | Std.IterStep.skip it => none | Std.IterStep.done => none