CompleteIfSome
CompleteIfSome is a polymorphic singleton Decoration that stops the pipeline as soon as
the decorated stage produces a value. It works by appending Complete via ~>: when the stage
yields Yield.Some, Complete immediately emits
Status.Complete; when the stage yields Yield.None, Complete is skipped and the
pipeline continues normally.
CompleteIfSome[I, O, E] returns a typed Decoration[I, O, E] that can be applied to any matching stage.
import h8io.stages.operators.*
import h8io.stages.projections.*
val stage = Unlift[Int]
// stage: h8io.stages.base.Projection[Option[Int], Int] = <function1>
val completing = CompleteIfSome[Option[Int], Int, Nothing](stage)
// completing: h8io.stages.Stage[Option[Int], Int, Nothing] = AndThen(
// upstream = <function1>,
// downstream = <function1>
// )
completing(Some(42)) // Unlift produces Some(42), Complete fires: Some(42, Complete, ...)
// res0: h8io.stages.Yield[Option[Int], Int, Nothing] = Some(
// out = 42,
// status = Complete(),
// evolution = AndThen(upstream = <function1>, downstream = <function1>)
// )
completing(None) // Unlift produces None, Complete skipped: None(Success, ...)
// res1: h8io.stages.Yield[Option[Int], Int, Nothing] = None(
// status = Success,
// evolution = AndThen(upstream = <function1>, downstream = <function1>)
// )