Loop consumers #
This module provides consumers that iterate over a given iterator, applying a certain user-supplied function in every iteration. Concretely, the following operations are provided:
ForIninstancesIter.fold, the analogue ofList.foldlIter.foldM, the analogue ofList.foldlM
These operations are implemented using the IteratorLoop type class.
A ForIn' instance for iterators. Its generic membership relation is not easy to use,
so this is not marked as instance. This way, more convenient instances can be built on top of it
or future library improvements will make it more comfortable.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
An implementation of for h : ... in ... do ... notation for partial iterators.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A ForIn' instance for iterators that is guaranteed to terminate after finitely many steps.
It is not marked as an instance because the membership predicate is difficult to work with.
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.
Equations
- One or more equations did not get rendered due to their size.
Folds a monadic function over an iterator from the left, accumulating a value starting with init.
The accumulated value is combined with the each element of the list in order, using f.
It is equivalent to it.toList.foldlM.
Equations
- Std.Iterators.Iter.foldM f init it = forIn it init fun (x : β) (acc : γ) => ForInStep.yield <$> f acc x
Instances For
Folds a monadic function over an iterator from the left, accumulating a value starting with init.
The accumulated value is combined with the each element of the list in order, using f.
It is equivalent to it.toList.foldlM.
This function is deprecated. Instead of it.allowNontermination.foldM, use it.foldM.
Equations
- Std.Iterators.Iter.Partial.foldM f init it = Std.Iterators.Iter.foldM f init it.it
Instances For
Folds a monadic function over an iterator from the left, accumulating a value starting with init.
The accumulated value is combined with the each element of the list in order, using f.
It is equivalent to it.toList.foldlM.
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 Iter.foldM.
Equations
- Std.Iterators.Iter.Total.foldM f init it = Std.Iterators.Iter.foldM f init it.it
Instances For
Folds a function over an iterator from the left, accumulating a value starting with init.
The accumulated value is combined with the each element of the list in order, using f.
It is equivalent to it.toList.foldl.
Equations
- Std.Iterators.Iter.fold f init it = forIn it init fun (x : β) (acc : γ) => ForInStep.yield (f acc x)
Instances For
Folds a function over an iterator from the left, accumulating a value starting with init.
The accumulated value is combined with the each element of the list in order, using f.
It is equivalent to it.toList.foldl.
This function is deprecated. Instead of it.allowNontermination.fold, use it.fold.
Equations
- Std.Iterators.Iter.Partial.fold f init it = Std.Iterators.Iter.fold f init it.it
Instances For
Folds a function over an iterator from the left, accumulating a value starting with init.
The accumulated value is combined with the each element of the list in order, using f.
It is equivalent to it.toList.foldl.
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 Iter.fold.
Equations
- Std.Iterators.Iter.Total.fold f init it = Std.Iterators.Iter.fold f init it.it
Instances For
Returns true if the monadic predicate p returns true for
any element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
Equations
Instances For
Returns true if the monadic predicate p returns true for
any element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
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 Iter.anyM.
Equations
Instances For
Returns true if the pure predicate p returns true for
any element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
Equations
- Std.Iterators.Iter.any p it = (Std.Iterators.Iter.anyM (fun (x : β) => pure (p x)) it).run
Instances For
Returns true if the pure predicate p returns true for
any element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
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 Iter.any.
Equations
Instances For
Returns true if the monadic predicate p returns true for
all element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
Equations
Instances For
Returns true if the monadic predicate p returns true for
all element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
This variant terminates after finitely mall steps and requires a proof that the iterator is
finite. If such a proof is not available, consider using Iter.allM.
Equations
Instances For
Returns true if the pure predicate p returns true for
all element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
Equations
- Std.Iterators.Iter.all p it = (Std.Iterators.Iter.allM (fun (x : β) => pure (p x)) it).run
Instances For
Returns true if the pure predicate p returns true for
all element emitted by the iterator it.
O(|xs|). Short-circuits upon encountering the first match. The elements in it are
examined in order of iteration.
This variant terminates after finitely mall steps and requires a proof that the iterator is
finite. If such a proof is not available, consider using Iter.all.
Equations
Instances For
Returns the first non-none result of applying the monadic function f to each output
of the iterator, in order. Returns none if f returns none for all outputs.
O(|it|). Short-circuits when f returns some _. The outputs of it are
examined in order of iteration.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.findSomeM? always terminates after finitely many steps.
Example:
#eval [7, 6, 5, 8, 1, 2, 6].iter.findSomeM? fun i => do
if i < 5 then
return some (i * 10)
if i ≤ 6 then
IO.println s!"Almost! {i}"
return none
Almost! 6
Almost! 5
some 10
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns the first non-none result of applying the monadic function f to each output
of the iterator, in order. Returns none if f returns none for all outputs.
O(|it|). Short-circuits when f returns some _. The outputs of it are
examined in order of iteration.
This function is deprecated. Instead of it.allowNontermination.findSomeM?, use it.findSomeM?.
Example:
#eval [7, 6, 5, 8, 1, 2, 6].iter.findSomeM? fun i => do
if i < 5 then
return some (i * 10)
if i ≤ 6 then
IO.println s!"Almost! {i}"
return none
Almost! 6
Almost! 5
some 10
Equations
- it.findSomeM? f = it.it.findSomeM? f
Instances For
Returns the first non-none result of applying the monadic function f to each output
of the iterator, in order. Returns none if f returns none for all outputs.
O(|it|). Short-circuits when f returns some _. The outputs of it are
examined in order of iteration.
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 Iter.findSomeM?.
Example:
#eval [7, 6, 5, 8, 1, 2, 6].iter.findSomeM? fun i => do
if i < 5 then
return some (i * 10)
if i ≤ 6 then
IO.println s!"Almost! {i}"
return none
Almost! 6
Almost! 5
some 10
Equations
- it.findSomeM? f = it.it.findSomeM? f
Instances For
Returns the first non-none result of applying f to each output of the iterator, in order.
Returns none if f returns none for all outputs.
O(|it|). Short-circuits when f returns some _.The outputs of it are examined in order of
iteration.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.findSome? always terminates after finitely many steps.
Examples:
[7, 6, 5, 8, 1, 2, 6].iter.findSome? (fun x => if x < 5 then some (10 * x) else none) = some 10[7, 6, 5, 8, 1, 2, 6].iter.findSome? (fun x => if x < 1 then some (10 * x) else none) = none
Equations
- it.findSome? f = (it.findSomeM? fun (x : β) => pure (f x)).run
Instances For
Returns the first non-none result of applying f to each output of the iterator, in order.
Returns none if f returns none for all outputs.
O(|it|). Short-circuits when f returns some _.The outputs of it are examined in order of
iteration.
This function is deprecated. Instead of it.allowNontermination.findSome?, use it.findSome?.
Examples:
[7, 6, 5, 8, 1, 2, 6].iter.allowNontermination.findSome? (fun x => if x < 5 then some (10 * x) else none) = some 10[7, 6, 5, 8, 1, 2, 6].iter.allowNontermination.findSome? (fun x => if x < 1 then some (10 * x) else none) = none
Instances For
Returns the first non-none result of applying f to each output of the iterator, in order.
Returns none if f returns none for all outputs.
O(|it|). Short-circuits when f returns some _.The outputs of it are examined in order of
iteration.
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 Iter.findSome?.
Examples:
[7, 6, 5, 8, 1, 2, 6].iter.ensureTermination.findSome? (fun x => if x < 5 then some (10 * x) else none) = some 10[7, 6, 5, 8, 1, 2, 6].iter.ensureTermination.findSome? (fun x => if x < 1 then some (10 * x) else none) = none
Instances For
Returns the first output of the iterator for which the monadic predicate p returns true, or
none if no such element is found.
O(|it|). Short-circuits when f returns true. The outputs of it are examined in order of
iteration.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.findM? always terminates after finitely many steps.
Example:
#eval [7, 6, 5, 8, 1, 2, 6].iter.findM? fun i => do
if i < 5 then
return true
if i ≤ 6 then
IO.println s!"Almost! {i}"
return false
Almost! 6
Almost! 5
some 1
Equations
Instances For
Returns the first output of the iterator for which the monadic predicate p returns true, or
none if no such element is found.
O(|it|). Short-circuits when f returns true. The outputs of it are examined in order of
iteration.
This function is deprecated. Instead of it.ensureTermination.findM?, use it.findM?.
Example:
#eval [7, 6, 5, 8, 1, 2, 6].iter.findM? fun i => do
if i < 5 then
return true
if i ≤ 6 then
IO.println s!"Almost! {i}"
return false
Almost! 6
Almost! 5
some 1
Instances For
Returns the first output of the iterator for which the monadic predicate p returns true, or
none if no such element is found.
O(|it|). Short-circuits when f returns true. The outputs of it are examined in order of
iteration.
This variant requires terminates after finitely many steps and requires a proof that the iterator is
finite. If such a proof is not available, consider using Iter.findM?.
Example:
#eval [7, 6, 5, 8, 1, 2, 6].iter.findM? fun i => do
if i < 5 then
return true
if i ≤ 6 then
IO.println s!"Almost! {i}"
return false
Almost! 6
Almost! 5
some 1
Instances For
Returns the first output of the iterator for which the predicate p returns true, or none if
no such output is found.
O(|it|). Short-circuits upon encountering the first match. The elements in it are examined in
order of iteration.
If the iterator is not finite, this function might run forever. The variant
it.ensureTermination.find? always terminates after finitely many steps.
Examples:
Instances For
Returns the first output of the iterator for which the predicate p returns true, or none if
no such output is found.
O(|it|). Short-circuits upon encountering the first match. The elements in it are examined in
order of iteration.
This function is deprecated. Instead of it.allowNontermination.find?, use it.find?.
Examples:
[7, 6, 5, 8, 1, 2, 6].iter.allowNontermination.find? (· < 5) = some 1[7, 6, 5, 8, 1, 2, 6].iter.allowNontermination.find? (· < 1) = none
Instances For
Returns the first output of the iterator for which the predicate p returns true, or none if
no such output is found.
O(|it|). Short-circuits upon encountering the first match. The elements in it are examined in
order of iteration.
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 Iter.find?.
Examples:
Instances For
Steps through the whole iterator, counting the number of outputs emitted.
Performance:
This function's runtime is linear in the number of steps taken by the iterator.
Instances For
Steps through the whole iterator, counting the number of outputs emitted.
Performance:
This function's runtime is linear in the number of steps taken by the iterator.
Instances For
Steps through the whole iterator, counting the number of outputs emitted.
Performance:
This function's runtime is linear in the number of steps taken by the iterator.
Instances For
Steps through the whole iterator, counting the number of outputs emitted.
Performance:
This function's runtime is linear in the number of steps taken by the iterator.