mapFailure

infix inline fun <Ok : Any, ErrorIn : Any, ErrorOut : Any> Outcome<Ok, ErrorIn>.mapFailure(transform: (ErrorIn) -> 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 flatMapFailure, mapFailure's transform lambda returns the monad's internal value directly instead of the Outcome wrapper.

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 ErrorOut value.

See also