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:

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$19885/0x00007f58029b4fb0@575effc8
//   )
// )
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$19886/0x00007f58029b5380@7eb6d003
//   )
// )
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$19887/0x00007f58029b5750@1b4cdc85
//   )
// )