Outcome
Outcome
is a type that represents three possible states a result can be in: Present, Absent or Failure. Under the hood it wraps the type Either<E, Option<A>>
and supports the common functions that Eithers and Options support such as map
, flatMap
and zip
.
There are three primary constructors:
data class Present<A>(val value: A) : Outcome<Nothing, A>
data class Failure<E>(val error: E) : Outcome<E, Nothing>
object Absent : Outcome<Nothing, Nothing>
Content copied to clipboard
or you can use the extension methods thusly:
A.present()
E.failure()
Content copied to clipboard
You can also easily convert an Either<Option<A>>
to an Outcome using toOutcome()
val outcome = "hi".some().right().toOutcome()
Content copied to clipboard
There is also a type alias OutcomeOf<A>
which specialises the error side to a Throwable
for your convenience.
Inheritors
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Zip allows you to combine two or more Outcome
s easily with a supplied function.
inline fun <E, A, B, C, D> Outcome<E, A>.zip(o1: Outcome<E, B>, o2: Outcome<E, C>, crossinline f: (A, B, C) -> D): Outcome<E, D>