Documentation

Std.Data.Iterators.Combinators.Monadic.Take

This module provides the iterator combinator IterM.take.

@[unbox]
structure Std.Iterators.Take (α : Type w) (m : Type w → Type w') (β : Type w) :

The internal state of the IterM.take iterator combinator.

  • remaining : Nat

    Internal implementation detail of the iterator library

  • inner : IterM m β

    Internal implementation detail of the iterator library

Instances For
    @[inline]
    def Std.Iterators.IterM.take {α : Type w} {m : Type w → Type w'} {β : Type w} (n : Nat) (it : IterM m β) :
    IterM m β

    Given an iterator it and a natural number n, it.take n is an iterator that outputs up to the first n of it's values in order and then terminates.

    Marble diagram:

    it          ---a----b---c--d-e--⊥
    it.take 3   ---a----b---c⊥
    
    it          ---a--⊥
    it.take 3   ---a--⊥
    

    Termination properties:

    • Finite instance: only if it is productive
    • Productive instance: only if it is productive

    Performance:

    This combinator incurs an additional O(1) cost with each output of it.

    Equations
    Instances For
      theorem Std.Iterators.IterM.take.surjective {α : Type w} {m : Type w → Type w'} {β : Type w} (it : IterM m β) :
      (it₀ : IterM m β), (k : Nat), it = take k it₀
      inductive Std.Iterators.Take.PlausibleStep {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] (it : IterM m β) (step : IterStep (IterM m β) β) :
      Instances For
        @[inline]
        instance Std.Iterators.Take.instIterator {α : Type w} {m : Type w → Type w'} {β : Type w} [Monad m] [Iterator α m β] :
        Iterator (Take α m β) m β
        Equations
        • One or more equations did not get rendered due to their size.
        def Std.Iterators.Take.Rel {α β : Type w} (m : Type w → Type w') [Monad m] [Iterator α m β] [Productive α m] :
        IterM m βIterM m βProp
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Std.Iterators.Take.rel_of_remaining {α : Type w} {m : Type w → Type w'} {β : Type w} [Monad m] [Iterator α m β] [Productive α m] {it it' : IterM m β} (h : it'.internalState.remaining < it.internalState.remaining) :
          Rel m it' it
          theorem Std.Iterators.Take.rel_of_inner {α : Type w} {m : Type w → Type w'} {β : Type w} [Monad m] [Iterator α m β] [Productive α m] {remaining : Nat} {it it' : IterM m β} (h : it'.finitelyManySkips.Rel it.finitelyManySkips) :
          Rel m (IterM.take remaining it') (IterM.take remaining it)
          instance Std.Iterators.Take.instFinite {α : Type w} {m : Type w → Type w'} {β : Type w} [Monad m] [Iterator α m β] [Productive α m] :
          Finite (Take α m β) m
          instance Std.Iterators.Take.instIteratorFor {α : Type w} {m : Type w → Type w'} {n : Type w → Type w''} {β : Type w} [Monad m] [Monad n] [Iterator α m β] [IteratorLoop α m n] [MonadLiftT m n] :
          IteratorLoop (Take α m β) m n
          Equations
          • One or more equations did not get rendered due to their size.
          instance Std.Iterators.Take.instIteratorForPartial {α : Type w} {m : Type w → Type w'} {n : Type w → Type w''} {β : Type w} [Monad m] [Monad n] [Iterator α m β] [IteratorLoopPartial α m n] [MonadLiftT m n] :
          Equations
          • One or more equations did not get rendered due to their size.