coerceToSuccess

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

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

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

  • If the receiver Outcome is an 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 Success<Ok> with the transformed value.

Parameters

Ok

The Ok type of Success.

Error

The Error type of the receiver Outcome.

recover

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

See also