This module provides the iterator combinator IterM.take.
The internal state of the IterM.take iterator combinator.
- countdown : Nat
- inner : IterM m β
Internal implementation detail of the iterator library
Internal implementation detail of the iterator library. This proof term ensures that a
takealways produces a finite iterator from a productive one.
Instances For
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:
Finiteinstance: only ifitis productiveProductiveinstance: only ifitis productive
Performance:
This combinator incurs an additional O(1) cost with each output of it.
Equations
- Std.Iterators.IterM.take n it = Std.Iterators.toIterM { countdown := n + 1, inner := it, finite := ⋯ } m β
Instances For
This combinator is only useful for advanced use cases.
Given a finite iterator it, returns an iterator that behaves exactly like it but is of the same
type as it.take n.
Marble diagram:
it ---a----b---c--d-e--⊥
it.toTake ---a----b---c--d-e--⊥
Termination properties:
Finiteinstance: alwaysProductiveinstance: always
Performance:
This combinator incurs an additional O(1) cost with each output of it.
Equations
- it.toTake = Std.Iterators.toIterM { countdown := 0, inner := it, finite := ⋯ } m β
Instances For
- yield {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] {it : IterM m β} {it' : IterM m β} {out : β} : it.internalState.inner.IsPlausibleStep (IterStep.yield it' out) → ∀ (h : it.internalState.countdown ≠ 1), PlausibleStep it (IterStep.yield { internalState := { countdown := it.internalState.countdown - 1, inner := it', finite := ⋯ } } out)
- skip {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] {it : IterM m β} {it' : IterM m β} : it.internalState.inner.IsPlausibleStep (IterStep.skip it') → it.internalState.countdown ≠ 1 → PlausibleStep it (IterStep.skip { internalState := { countdown := it.internalState.countdown, inner := it', finite := ⋯ } })
- done {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] {it : IterM m β} : it.internalState.inner.IsPlausibleStep IterStep.done → PlausibleStep it IterStep.done
- depleted {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] {it : IterM m β} : it.internalState.countdown = 1 → PlausibleStep it IterStep.done