Outcome

sealed class Outcome<out Failure, out Value>(source)

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

Link copied to clipboard
data class Failure<Failure>(val failure: Failure) : Outcome<Failure, Nothing>

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

Link copied to clipboard
data class Success<Value>(val value: Value) : Outcome<Nothing, Value>

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

Properties

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard

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

Functions

Link copied to clipboard

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

Link copied to clipboard

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

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

Executes block if this outcome is a failure.

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

Executes block if this outcome is successful.

Link copied to clipboard

Converts an Outcome into a typed Either.

Link copied to clipboard

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