Collectors #
This module provides consumers that collect the values emitted by an iterator in a data structure. Concretely, the following operations are provided:
IterM.toList, collecting the values in a listIterM.toListRev, collecting the values in a list in reverse order but more efficientlyIterM.toArray, collecting the values in an array
Some producers and combinators provide specialized implementations. These are captured by the
IteratorCollect type class. They should be implemented by all types of iterators. A default
implementation is provided. The typeclass LawfulIteratorCollect asserts that an IteratorCollect
instance equals the default implementation.
IteratorCollect α m provides efficient implementations of collectors for α-based
iterators. Right now, it is limited to a potentially optimized toArray implementation.
This class is experimental and users of the iterator API should not explicitly depend on it. They can, however, assume that consumers that require an instance will work for all iterators provided by the standard library.
Note: For this to be compositional enough to be useful, toArrayMapped would need to accept a
termination proof for the specific mapping function used instead of the blanket Finite α m
instance. Otherwise, most combinators like map cannot implement their own instance relying on
the instance of their base iterators. However, fixing this is currently low priority.
Instances
This is an internal function used in IteratorCollect.defaultImplementation.
It iterates over an iterator and applies f whenever a value is emitted before inserting the result
of f into an array.
Equations
Instances For
This is the default implementation of the IteratorCollect class.
It simply iterates through the iterator using IterM.step, incrementally building up the desired
data structure. For certain iterators, more efficient implementations are possible and should be
used instead.
Equations
Instances For
Asserts that a given IteratorCollect instance is equal to IteratorCollect.defaultImplementation
if the underlying iterator is finite.
(Even though equal, the given instance might be vastly more efficient.)
- lawful_toArrayMapped {γ : Type w} (lift : ⦃α : Type w⦄ → m α → n α) [Internal.LawfulMonadLiftFunction lift] [Finite α m] : IteratorCollect.toArrayMapped lift = IteratorCollect.toArrayMapped lift
Instances
Traverses the given iterator and stores the emitted values in an array.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.toArray always terminates after finitely many steps.
Equations
Instances For
Traverses the given iterator and stores the emitted values in an array.
This function is deprecated. Instead of it.allowNontermination.toArray, use it.toArray.
Instances For
Traverses the given iterator and stores the emitted values in an array.
This variant terminates after finitely many steps and requires a proof that the iterator is
finite. If such a proof is not available, consider using IterM.toArray.
Instances For
Traverses the given iterator and stores the emitted values in reverse order in a list. Because
lists are prepend-only, this toListRev is usually more efficient that toList.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.toListRev always terminates after finitely many steps.
Equations
Instances For
Traverses the given iterator and stores the emitted values in reverse order in a list. Because
lists are prepend-only, this toListRev is usually more efficient that toList.
This function is deprecated. Instead of it.allowNontermination.toListRev, use it.toListRev.
Instances For
Traverses the given iterator and stores the emitted values in reverse order in a list. Because
lists are prepend-only, this toListRev is usually more efficient that toList.
This variant terminates after finitely many steps and requires a proof that the iterator is
finite. If such a proof is not available, consider using IterM.toListRev.
Instances For
Traverses the given iterator and stores the emitted values in a list. Because
lists are prepend-only, toListRev is usually more efficient that toList.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.toList always terminates after finitely many steps.
Equations
- it.toList = Array.toList <$> it.toArray
Instances For
Traverses the given iterator and stores the emitted values in a list. Because
lists are prepend-only, toListRev is usually more efficient that toList.
This function is deprecated. Instead of it.allowNontermination.toList, use it.toList.
Instances For
Traverses the given iterator and stores the emitted values in a list. Because
lists are prepend-only, toListRev is usually more efficient that toList.
This variant terminates after finitely many steps and requires a proof that the iterator is
finite. If such a proof is not available, consider using IterM.toList.