coerceToSuccess

infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.coerceToSuccess(recover: (Error) -> Ok): Outcome.Success<Ok>

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

  • Transforms Outcome<Ok, Error> into Outcome.Success<Ok>.

  • If the receiver Outcome is an Outcome.Success, nothing happens.

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

Receiver

The Outcome<Ok, Error> to transform.

Return

A new Outcome.Success<Ok> with the transformed value.

Parameters

Ok

The Ok type of Outcome.Success.

Error

The Error type of the receiver Outcome.

recover

The transform function to convert an Error value into an Ok value.

See also