flatMapFailure

infix inline fun <Ok : Any, ErrorIn : Any, ErrorOut : Any> Outcome<Ok, ErrorIn>.flatMapFailure(transform: (ErrorIn) -> Outcome<Ok, ErrorOut>): Outcome<Ok, ErrorOut>

Returns a new Outcome, after applying transform to the Outcome.Failure error.

  • Transforms Outcome<Ok, ErrorIn> into Outcome<Ok, ErrorOut>.

  • If the receiver Outcome is an Outcome.Success, the Ok is simply re-wrapped to update the Error type.

  • This function does not provide a RaiseScope, and makes no guarantees about catching, handling, or rethrowing errors! Use tryRecover or outcomeOf within the transformation lambda for that.

  • Unlike mapFailure, flatMapFailure's transform lambda returns the Outcome wrapper directly instead of the monad's internal value.

Receiver

The Outcome<Ok, ErrorIn> to transform.

Return

A new Outcome<Ok, ErrorOut> with the transformed error.

Parameters

Ok

The Ok type of Outcome.Success.

ErrorIn

The Error type of the receiver Outcome.

ErrorOut

The Error type of the returned Outcome.

transform

The transform function to convert an ErrorIn value into an Outcome.

See also