fold
inline fun <Ok, Error, Output> Outcome<Ok, Error>.fold(failure: Failure<Error>.() -> Output, success: Success<Ok>.() -> Output): Output
Applies success or failure to the receiver Outcome, returning Output.
Unlike map, Output is unconstrained — it need not be an Outcome.
When Output is itself an Outcome,
folddoubles as a flatMap over both states.Use collapse when the Success value and Failure error share a common ancestor and no transformation is needed.
Parameters
success
Lambda applied when the receiver is a Success.
failure
Lambda applied when the receiver is a Failure.