Documentation

Init.Data.Range.Polymorphic.RangeIterator

Range iterator #

This module implements an iterator for ranges (Std.PRange).

This iterator is publicly available via PRange.iter after importing Std.Data.Iterators and it internally powers many functions on ranges such as PRange.toList.

@[unbox]
structure Std.PRange.RangeIterator (shape : BoundShape) (α : Type u) :

Internal state of the range iterators. Do not depend on its internals.

Instances For
    @[inline]

    The pure function mapping a range iterator of type IterM to the next step of the iterator.

    This function is prefixed with Monadic in order to disambiguate it from the version for iterators of type Iter.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[inline]

      The pure function mapping a range iterator of type Iter to the next step of the iterator.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        @[inline]
        Equations
        • One or more equations did not get rendered due to their size.
        Equations
        • One or more equations did not get rendered due to their size.

        Efficient IteratorLoop instance #

        As long as the compiler cannot optimize away the Option in the internal state, we use a special loop implementation.

        @[inline]
        Equations
        • One or more equations did not get rendered due to their size.
        @[irreducible, specialize #[]]
        def Std.PRange.RangeIterator.instIteratorLoop.loop {α : Type u} {su : BoundShape} [UpwardEnumerable α] [SupportsUpperBound su α] [LawfulUpwardEnumerable α] {n : Type u → Type w} [Monad n] (γ : Type u) (Pl : αγForInStep γProp) (wf : Iterators.IteratorLoop.WellFounded (RangeIterator su α) Id Pl) (upperBound : Bound su α) (least : α) (acc : γ) (f : (out : α) → UpwardEnumerable.LE least outSupportsUpperBound.IsSatisfied upperBound out(c : γ) → n { s : ForInStep γ // Pl out c s }) (next : α) (hl : UpwardEnumerable.LE least next) (hu : SupportsUpperBound.IsSatisfied upperBound next) :
        n γ
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          Equations
          • One or more equations did not get rendered due to their size.
          @[specialize #[]]
          partial def Std.PRange.RepeatIterator.instIteratorLoopPartial.loop {α : Type u} {su : BoundShape} [UpwardEnumerable α] [SupportsUpperBound su α] [LawfulUpwardEnumerable α] {n : Type u → Type w} [Monad n] (γ : Type u) (upperBound : Bound su α) (least : α) (acc : γ) (f : (out : α) → UpwardEnumerable.LE least outSupportsUpperBound.IsSatisfied upperBound outγn (ForInStep γ)) (next : α) (hl : UpwardEnumerable.LE least next) (hu : SupportsUpperBound.IsSatisfied upperBound next) :
          n γ
          @[irreducible]
          theorem Std.PRange.RangeIterator.instIteratorLoop.loop_eq {α : Type u} {least : α} {su : BoundShape} [UpwardEnumerable α] [SupportsUpperBound su α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableUpperBound su α] {n : Type u → Type w} [Monad n] [LawfulMonad n] {γ : Type u} {lift : (γ δ : Type u) → (γn δ)Id γn δ} [Internal.LawfulMonadLiftBindFunction lift] {PlausibleForInStep : αγForInStep γProp} {upperBound : Bound su α} {next : α} {hl : UpwardEnumerable.LE least next} {hu : SupportsUpperBound.IsSatisfied upperBound next} {f : (out : α) → UpwardEnumerable.LE least outSupportsUpperBound.IsSatisfied upperBound out(c : γ) → n { s : ForInStep γ // PlausibleForInStep out c s }} {acc : γ} {wf : Iterators.IteratorLoop.WellFounded (RangeIterator su α) Id PlausibleForInStep} :
          loop γ PlausibleForInStep wf upperBound least acc f next hl hu = do let __do_liftf next hl hu acc match __do_lift with | ForInStep.yield c, property => Iterators.IterM.DefaultConsumers.forIn' lift γ PlausibleForInStep wf { internalState := { next := UpwardEnumerable.succ? next, upperBound := upperBound } } c { internalState := { next := UpwardEnumerable.succ? next, upperBound := upperBound } }.IsPlausibleIndirectOutput fun (b : α) (h : { internalState := { next := UpwardEnumerable.succ? next, upperBound := upperBound } }.IsPlausibleIndirectOutput b) (c : γ) => f b c | ForInStep.done c, property => pure c