coerceToFailure

infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.coerceToFailure(falter: (Ok) -> Error): Failure<Error>

Returns a new Failure, after applying falter to the Success value.

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

  • If the receiver Outcome is an Failure, 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 Failure<Nothing, Error> with the transformed error.

Parameters

Ok

The Ok type of the receiver Outcome.

Error

The Error type of Failure.

falter

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

See also