KeepLastOutput
KeepLastOutput remembers the last value produced by the inner stage and re-emits it when the inner stage
yields nothing.
The decorator has two states:
- Initial state (no value seen yet):
Yield.Noneis forwarded unchanged;Yield.Someis forwarded and transitions to the remembered state. - Remembered state: regardless of whether the inner stage yields
SomeorNone, the last known value is always emitted. A newYield.Someupdates the remembered value.
The factory KeepLastOutput(stage) always starts in the initial state.
import h8io.stages.operators.*
import h8io.stages.projections.*
val stage = KeepLastOutput(Unlift[Int])
// stage: h8io.stages.Stage[Option[Int], Int, Nothing] = None(
// alterand = <function1>
// )
val r1 = stage(Some(7)) // inner yields Some(7): emitted, value remembered
// r1: h8io.stages.Yield[Option[Int], Int, Nothing] = Some(
// out = 7,
// status = Success,
// evolution = Mapped(
// evolution = <function1>,
// f = h8io.stages.operators.KeepLastOutput$None$$Lambda$14354/0x00007f2c9263a618@2899574e
// )
// )
val r2 = r1.evolve()(None) // inner yields None: last value re-emitted
// r2: h8io.stages.Yield[Option[Int], Int, Nothing] = Some(
// out = 7,
// status = Success,
// evolution = Mapped(
// evolution = <function1>,
// f = h8io.stages.operators.KeepLastOutput$Some$$Lambda$14355/0x00007f2c9263a9e8@69ea27a8
// )
// )
val r3 = r2.evolve()(Some(3)) // inner yields Some(3): emitted, remembered value updated
// r3: h8io.stages.Yield[Option[Int], Int, Nothing] = Some(
// out = 3,
// status = Success,
// evolution = Mapped(
// evolution = <function1>,
// f = h8io.stages.operators.KeepLastOutput$Some$$Lambda$14356/0x00007f2c9263adb8@880d208
// )
// )