public class Iteration<T,R,I extends java.lang.Iterable<T>,C extends java.util.Collection<R>> extends CoroutineStep<I,C>
Iterable
input
value. Each value returned by the iterator will be processed with a separate
execution of a certain coroutine step (which may be a subroutine).
The static factory methods forEach(CoroutineStep)
, collectEach(CoroutineStep)
, and collectEachInto(Supplier,
CoroutineStep)
create instances that either discard or collect the results
of applying the iteration step.
Constructor and Description |
---|
Iteration(java.util.function.Supplier<C> fCollectionFactory,
CoroutineStep<T,R> rProcessingStep)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
static <T,R,I extends java.lang.Iterable<T>> |
collectEach(CoroutineStep<T,R> rProcessingStep)
Collects all processed elements into a list.
|
static <T,R,I extends java.lang.Iterable<T>,C extends java.util.Collection<R>> |
collectEachInto(java.util.function.Supplier<C> fCollectionFactory,
CoroutineStep<T,R> rProcessingStep)
Iterates over the elements in an
Iterable input value, processes
each element with another coroutine step, and collects the resulting
values into a target collection. |
protected C |
execute(I rInput,
Continuation<?> rContinuation)
This method must be implemented by subclasses to provide the actual
functionality of this step.
|
static <T,I extends java.lang.Iterable<T>> |
forEach(CoroutineStep<T,?> rProcessingStep)
Iterates over the elements in an
Iterable input value and
processes each element with another coroutine step. |
void |
runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution,
CoroutineStep<C,?> rNextStep,
Continuation<?> rContinuation)
Runs this execution step asynchronously as a continuation of a previous
code execution in a
CompletableFuture and proceeds to the next
step afterwards. |
fail, runBlocking, terminateCoroutine, toString
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public Iteration(java.util.function.Supplier<C> fCollectionFactory, CoroutineStep<T,R> rProcessingStep)
fCollectionFactory
- A supplier that returns a collection of the
target type to store the processed values in or
NULL for no collectionrProcessingStep
- The step to be applied to each value returned
by the iteratorpublic static <T,R,I extends java.lang.Iterable<T>> CoroutineStep<I,java.util.List<R>> collectEach(CoroutineStep<T,R> rProcessingStep)
collectEachInto(Supplier, CoroutineStep)
public static <T,R,I extends java.lang.Iterable<T>,C extends java.util.Collection<R>> CoroutineStep<I,C> collectEachInto(java.util.function.Supplier<C> fCollectionFactory, CoroutineStep<T,R> rProcessingStep)
Iterable
input value, processes
each element with another coroutine step, and collects the resulting
values into a target collection. If invoked asynchronously each iteration
will be invoked as a separate suspension, but values are still processed
sequentially. After the iteration has completed the coroutine continues
with the next step with the collected values as it's input.fCollectionFactory
- A supplier that returns a collection of the
target type to store the processed values inrProcessingStep
- The step to process each valuepublic static <T,I extends java.lang.Iterable<T>> CoroutineStep<I,java.lang.Void> forEach(CoroutineStep<T,?> rProcessingStep)
Iterable
input value and
processes each element with another coroutine step. The processed values
will be discarded, the returned step will always have a result of NULL.
To collect the processed values collectEachInto(Supplier,
CoroutineStep)
can be used instead.rProcessingStep
- The step to process each valuepublic void runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution, CoroutineStep<C,?> rNextStep, Continuation<?> rContinuation)
CompletableFuture
and proceeds to the next
step afterwards.
Subclasses that need to suspend the invocation of the next step until
some condition is met (e.g. sending or receiving data has finished) need
to override this method and create a Suspension
by invoking
Continuation.suspend(CoroutineStep, CoroutineStep)
on the next
step. If the condition that caused the suspension resolves the coroutine
execution can be resumed by calling Suspension.resume(Object)
.
Subclasses that override this method also need to handle errors by
terminating any further execution (i.e. not resuming a suspension if such
exists) and forwarding the causing exception to Continuation.fail(Throwable)
.
protected C execute(I rInput, Continuation<?> rContinuation)