Fn

Fn is the simplest way to turn a single pure function into a Stage: extend Fn and implement f. Everything else — wrapping in Yield.Some, attaching Status.Success, wiring the evolution — is handled automatically.

As the most constrained member of the hierarchy, a Fn stage can never produce Yield.None or a non-Success status. When output is not always guaranteed or a different status is needed, use StaticStage instead.

import h8io.stages.base.*
object DoubleInt extends Fn[Int, Int] {
  override protected def f(in: Int): Int = in * 2
}

DoubleInt(21)
// res0: h8io.stages.Yield.Some[Int, Int, Nothing] = Some(
//   out = 42,
//   status = Success,
//   evolution = <function1>
// )
DoubleInt.skip()
// res1: h8io.stages.Evolution[Int, Int, Nothing] = <function1>

Fn also defines Fn.Endo[T] as a type alias for endomorphic stages that map a type to itself.