Loop
A decorator that feeds the output of each successful step back as the input of the next, effectively looping the inner endomorphic stage until it stops.
The tail-recursive loop works as follows:
h8io.stages.Status.Success+h8io.stages.Yield.Some: the output becomes the new input and the loop continues with the stage selected byyld.evolve().h8io.stages.Status.Success+h8io.stages.Yield.None: no output was produced; the loop stops and emits aYield.NonewithSuccessstatus whose continuation is the stage selected byyld.evolve(), wrapped back inLoop.h8io.stages.Status.Completewith no errors: the loop stops, converts the status back toSuccess, and wraps the stage selected byyld.evolve()inLoopfor the next outer invocation.h8io.stages.Status.Completewith errors: the loop stops, preserves the errors, and selects the continuation the same way.
In every branch the continuation of the inner stage is selected by the status the inner stage itself produced, and never by the status Loop reports to the enclosing pipeline — the two differ, since an error-free Complete is absorbed into a Success. For the same reason the returned evolution is a h8io.stages.base.ConstEvolution: the status the enclosing pipeline evolves Loop with belongs to that pipeline, not to the inner stage, and must not be passed inwards. Symmetrically, a skipped Loop skips its inner stage and selects the inner continuation on the neutral Status.Success. The returned ConstEvolution keeps the inner evolution's dispose as its own: per the h8io.stages.Evolution contract, the inner evolution stays the terminal cleanup handle for the generation constructed here until that generation runs.
This makes Loop suitable for in-process iterative computations (e.g., fixed-point iterations) where the result of one step seeds the next.
Type parameters
- E
-
the error type (covariant)
- T
-
the value type (both input and output)
Value parameters
- alterand
-
the inner endomorphic stage
T → Tto loop
Attributes
- Graph
-
- Supertypes