Skip to content

Outcome

sealed class Outcome<out Failure, out Value>

The result of an operation.

To store progress information as well as the result of the operation, please see ProgressiveOutcome.

There are two possible cases:

To create outcomes from computations, use the successful and failed factories.

Arrow

Outcome is essentially identical to Arrow's Either. When using Arrow, we recommend using Either most of the time because of all the convenience functions and DSLs it has. Using our companion library state-arrow, it is possible to use Outcome in the Raise DSL.

Because of this, we will keep Outcome as simple as possible, and avoid adding too much sugar.

Inheritors

Types

Failure

data class Failure<Failure>(val failure: Failure) : Outcome<Failure, Nothing> 

The latest known result of the operation was a failure, available as failure.

Success

data class Success<Value>(val value: Value) : Outcome<Nothing, Value> 

The latest known result of the operation was a success, available as value.

Properties

failure

failureOrNull

Returns Failure.failure, or null if this outcome is not a failure.

value

valueOrNull

Returns Success.value, or null if this outcome is not successful.

Functions

map

If this outcome is successful, replaces its value using transform.

If this outcome isn't successful, does nothing.

See also

  • mapFailure: Map the failure state instead of the success state.

mapFailure

If this outcome is failed, replaces its failure using transformFailure.

If this outcome isn't failed, does nothing.

See also

  • map: Map the success state instead of the failure state.

onFailure

inline fun <Failure> Outcome<Failure, *>.onFailure(block: (Failure) -> Unit)

Executes block if this outcome is a failure.

Otherwise, does nothing.

onSuccess

inline fun <Value> Outcome<*, Value>.onSuccess(block: (Value) -> Unit)

Executes block if this outcome is successful.

Otherwise, does nothing.

toEither

Converts an Outcome into a typed Either.

withProgress

Adds progress information to this outcome to make it a ProgressiveOutcome.