CompleteIfNone
CompleteIfNone is a decorator that stops the pipeline when the inner stage produces no output.
When the inner stage yields Yield.None with a
Status.Success status, CompleteIfNone upgrades the status to
Status.Complete, signalling that processing should not continue. All other yields
are forwarded unchanged. The evolution is mapped in both cases so that continuations remain wrapped in
CompleteIfNone.
This is useful for stages that return None when their input stream is exhausted — wrapping them with
CompleteIfNone turns the absence of output into a clean pipeline termination.
import h8io.stages.*
import h8io.stages.base.*
import h8io.stages.operators.*
object FindPositive extends SAMStage[Int, Int, Nothing] {
override def apply(in: Int): Yield[Int, Int, Nothing] =
if (in > 0) Yield.Some(in, Status.Success, this) else Yield.None(Status.Success, this)
}
val stage = CompleteIfNone(FindPositive)
// stage: CompleteIfNone[Int, Int, Nothing] = CompleteIfNone(
// alterand = <function1>
// )
stage(5) // inner yields Some: forwarded unchanged
// res0: Yield[Int, Int, Nothing] = Some(
// out = 5,
// status = Success,
// evolution = Mapped(
// evolution = <function1>,
// f = h8io.stages.operators.CompleteIfNone$$Lambda$14352/0x00007f2c92638000@50b2bc9
// )
// )
stage(-3) // inner yields None(Success): upgraded to None(Complete)
// res1: Yield[Int, Int, Nothing] = None(
// status = Complete(),
// evolution = Mapped(
// evolution = <function1>,
// f = h8io.stages.operators.CompleteIfNone$$Lambda$14353/0x00007f2c926383c8@674490ff
// )
// )