Package-level declarations

Custom types (e.g. Outcome)

Types

Link copied to clipboard
data object Absent : Outcome<Nothing, Nothing>
Link copied to clipboard
data class Failure<E>(val error: E) : Outcome<E, Nothing>
Link copied to clipboard
sealed class Outcome<out E, out A>

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.

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

A data class representing the Presence of a value A.

Functions

Link copied to clipboard
inline fun <E, A> Outcome<E, A>.asEither(onAbsent: () -> E): Either<E, A>
Link copied to clipboard
fun <E, A> Outcome<E, A>.asOption(): Option<A>

Converts an Outcome to an option treating Failure as Absent

Link copied to clipboard
fun <E, A> Either<E, A>.asOutcome(): Outcome<E, A>
Link copied to clipboard
Link copied to clipboard
fun <E> E.failure(): Outcome<E, Nothing>
Link copied to clipboard
inline fun <A, E> Outcome<E, A>.filter(p: (A) -> Boolean): Outcome<E, A>
Link copied to clipboard
inline fun <A, E, B> Outcome<E, A>.flatMap(f: (A) -> Outcome<E, B>): Outcome<E, B>

FlatMap allows multiple Outcomes to be safely chained together, passing the value from the previous as input into the next function that produces an Outcome

Link copied to clipboard
inline fun <A, E, B> Outcome<E, A>.flatTap(f: (A) -> Outcome<E, B>): Outcome<E, A>

Performs a flatMap across the supplied function, propagating failures or absence but preserving the original present value.

Link copied to clipboard
fun <A, E> Outcome<E, Outcome<E, A>>.flatten(): Outcome<E, A>
Link copied to clipboard
inline fun <E, A, B> Outcome<E, A>.fold(onFailure: (E) -> B, onAbsent: () -> B, onPresent: (A) -> B): B
Link copied to clipboard
inline fun <E, A, B> Outcome<E, A>.foldOption(onAbsent: () -> B, onPresent: (A) -> B): Either<E, B>
Link copied to clipboard
inline fun <E, A> Outcome<E, A>.getOrElse(onAbsentOrFailure: () -> A): A
Link copied to clipboard
inline fun <E, A, EE> Outcome<E, A>.mapFailure(f: (E) -> EE): Outcome<EE, A>
Link copied to clipboard
inline fun <E, A> Outcome<E, A>.onAbsentHandle(onAbsent: () -> Outcome<E, A>): Outcome<E, A>
Link copied to clipboard
inline fun <E, A> Outcome<E, A>.onFailureHandle(onFailure: (E) -> Outcome<E, A>): Outcome<E, A>
Link copied to clipboard
fun <A> Outcome<Throwable, A>.optionOrThrow(): Option<A>
Link copied to clipboard
inline fun <A> Outcome<Throwable, A>.orThrow(onAbsent: () -> Throwable): A
Link copied to clipboard
fun <A> A.present(): Outcome<Nothing, A>
Link copied to clipboard
inline fun <E, A, EE> Outcome<E, A>.recover(block: OutcomeRaise<EE>.(E) -> A): Outcome<EE, A>
Link copied to clipboard
fun <E, EE, A> Outcome<E, Either<EE, A>>.sequence(): Either<EE, Outcome<E, A>>
fun <E, A> Outcome<E, Option<A>>.sequence(): Option<Outcome<E, A>>
fun <E, EE, A> Outcome<E, Validated<EE, A>>.sequence(): Validated<EE, Outcome<E, A>>
Link copied to clipboard
inline fun <A, B, E> Outcome<E, A>.tapAbsent(f: () -> B): Outcome<E, A>
Link copied to clipboard
inline fun <A, B, E> Outcome<E, A>.tapFailure(f: (E) -> B): Outcome<E, A>
Link copied to clipboard
fun <E, A> Either<E, Option<A>>.toOutcome(): Outcome<E, A>

An extension method on Either> that converts it to an Outcome.

fun <A> Option<A>.toOutcome(): Outcome<Nothing, A>
Link copied to clipboard
inline fun <E, EE, A, B> Outcome<E, A>.traverse(f: (A) -> Either<EE, B>): Either<EE, Outcome<E, B>>
inline fun <E, A, B> Outcome<E, A>.traverse(f: (A) -> Option<B>): Option<Outcome<E, B>>
inline fun <E, EE, A, B> Outcome<E, A>.traverse(f: (A) -> Validated<EE, B>): Validated<EE, Outcome<E, B>>
inline fun <E, A, B> Outcome<E, A>.traverse(f: (A) -> List<B>): List<Outcome<E, B>>
Link copied to clipboard
inline fun <E, A, B, C> Outcome<E, A>.zip(other: Outcome<E, B>, f: (A, B) -> C): Outcome<E, C>

Zip allows you to combine two or more Outcomes 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>
inline fun <E, A, B, C, D, EE> Outcome<E, A>.zip(o1: Outcome<E, B>, o2: Outcome<E, C>, o3: Outcome<E, D>, crossinline f: (A, B, C, D) -> EE): Outcome<E, EE>
inline fun <E, A, B, C, D, EE, F> Outcome<E, A>.zip(o1: Outcome<E, B>, o2: Outcome<E, C>, o3: Outcome<E, D>, o4: Outcome<E, EE>, crossinline f: (A, B, C, D, EE) -> F): Outcome<E, F>