Documentation

Init.Data.Iterators.Consumers.Access

@[specialize #[]]
def Std.Iter.atIdxSlow? {α β : Type u_1} [Iterator α Id β] (n : Nat) (it : Iter β) :

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
    @[irreducible]
    theorem Std.Iter.atIdxSlow?.induct_unfolding {α β : Type u} [Iterator α Id β] [Iterators.Productive α Id] (motive : NatIter βOption βProp) (yield_zero : ∀ (it it' : Iter β) (out : β) (property : it.IsPlausibleStep (IterStep.yield it' out)), it.step = IterStep.yield it' out, propertymotive 0 it (some out)) (yield_succ : ∀ (it it' : Iter β) (out : β) (property : it.IsPlausibleStep (IterStep.yield it' out)), it.step = IterStep.yield it' out, property∀ (k : Nat), motive k it' (atIdxSlow? k it')motive k.succ it (atIdxSlow? k it')) (skip_case : ∀ (n : Nat) (it it' : Iter β) (property : it.IsPlausibleStep (IterStep.skip it')), it.step = IterStep.skip it', propertymotive n it' (atIdxSlow? n it')motive n it (atIdxSlow? n it')) (done_case : ∀ (n : Nat) (it : Iter β) (property : it.IsPlausibleStep IterStep.done), it.step = IterStep.done, propertymotive n it none) (n : Nat) (it : Iter β) :
    motive n it (atIdxSlow? n it)
    @[inline]
    def Std.Iter.Total.atIdxSlow? {α β : Type u_1} [Iterator α Id β] [Iterators.Productive α Id] (n : Nat) (it : Total β) :

    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
    Instances For
      @[inline, deprecated Std.Iter.atIdxSlow? (since := "2026-01-28")]
      def Std.Iter.Partial.atIdxSlow? {α β : Type u_1} [Iterator α Id β] (n : Nat) (it : Partial β) :

      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
      Instances For
        @[inline]
        def Std.Iter.atIdx? {α β : Type u_1} [Iterator α Id β] [IteratorAccess α Id] (n : Nat) (it : Iter β) :

        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
        Instances For