coerceToFailure

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

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

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

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

Parameters

Ok

The Ok type of the receiver Outcome.

Error

The Error type of Outcome.Failure.

falter

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

See also