fold

inline fun <Ok : Any, Error : Any, Output> Outcome<Ok, Error>.fold(failure: Failure<Error>.() -> Output, success: Success<Ok>.() -> Output): Output

Fold the caller into some Output.

  • Unlike map, fold places no restrictions on Output type.

  • If Output is Outcome, fold can be used to flatMap both outcomes.

  • Use collapse to assume the nearest common Ancestor as the Output type.

Receiver

The Outcome to collapse.

Return

The collapsed value of type Output.

Parameters

Ok

The type of the Success value.

Error

The type of the Failure error.

success

The lambda to transform the Success value into Output.

failure

The lambda to transform the Failure error into Output.

See also

collapse