Package-level declarations

Properties

Link copied to clipboard
val <T : Any> T.asFailure: Failure<T>

Wrap any T as an outcome Failure.

Link copied to clipboard

Convert any Outcome to a Faulty by transforming the Success.value to Unit.

Link copied to clipboard
val <Ok : Any> Outcome<Ok, *>.asMaybe: Maybe<Ok>

Convert any Outcome to a Maybe by transforming the Failure.error to Unit.

Link copied to clipboard
val <T : Any> T.asSuccess: Success<T>

Wrap any T as an outcome Success.

Link copied to clipboard

Wrap any T as a Faulty.

Link copied to clipboard
@get:JvmName(name = "flattenNestedFailureAlias")
val <Ok : Any, Err : Any, Oki : Ok, Oko : Ok> Outcome<Oko, Outcome<Oki, Err>>.flatten: Outcome<Ok, Err>

An overloaded alias for Outcome.flattenNestedFailure.

@get:JvmName(name = "flattenNestedBothAlias")
val <Ok : Any, Err : Any, Oks : Ok, Ers : Err, Okf : Ok, Erf : Err> Outcome<Outcome<Oks, Ers>, Outcome<Okf, Erf>>.flatten: Outcome<Ok, Err>

An overloaded alias for Outcome.flattenNestedBoth.

@get:JvmName(name = "flattenNestedSuccessAlias")
val <Ok : Any, Err : Any, Eri : Err, Ero : Err> Outcome<Outcome<Ok, Eri>, Ero>.flatten: Outcome<Ok, Err>

An overloaded alias for Outcome.flattenNestedSuccess.

Link copied to clipboard
val <T> T.maybe: Maybe<T & Any>

Wrap any T as an Maybe.

Link copied to clipboard

Wrap any T as an Outcome.

Functions

Link copied to clipboard
Link copied to clipboard
inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.andIf(predicate: (Ok) -> Boolean, catch: (throwable: Throwable) -> Outcome<Ok, Error> = ::rethrow, success: RaiseScope<Error>.(Ok) -> Ok): Outcome<Ok, Error>

Transforms the encapsulated value if this instance represents success, and the predicate returns true. If predicate is false, the Success is left unchanged.

Link copied to clipboard
inline fun <In : Any, Out : Any, Error : Any> Outcome<In, Error>.andThen(catch: (throwable: Throwable) -> Outcome<Out, Error> = ::rethrow, success: RaiseScope<Error>.(In) -> Out): Outcome<Out, Error>

Transforms the encapsulated value if this instance represents success.

Link copied to clipboard
inline fun <Ok : Any> catch(block: RaiseScope<Throwable>.() -> Ok): Outcome<Ok, Throwable>

An alias for outcomeOf that uses Throwable as the Error type.

Link copied to clipboard
inline fun <In, Out : Any> In.catch(block: RaiseScope<Throwable>.(In) -> Out): Outcome<Out, Throwable>

An alias for outcomeOf that uses Throwable as the Error type.

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

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

Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.coerceToSuccess(recover: (Error) -> Ok): Success<Ok>

Returns a new Success, after applying recover to the Failure error.

Link copied to clipboard

Collapse the receiver Outcome into either value or error, using the nearest common Ancestor as the type.

Link copied to clipboard
inline fun emptyFailure(ignore: Any? = null): Failure<Unit>

An inline hack to produce a Failure outcome with no error.

Link copied to clipboard
inline fun emptySuccess(ignore: Any? = null): Success<Unit>

An inline hack to produce a Success outcome with no value.

Link copied to clipboard
infix fun <Ok : Any, Error : Any> Outcome<Ok, Error>.errorOrDefault(default: Error): Error
Link copied to clipboard
infix inline fun <Ok : Any, Error> Outcome<Ok, Error & Any>.errorOrElse(faulter: (Ok) -> Error): Error
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun <Error : Any> failureOf(block: () -> Error): Failure<Error>

Builds a Failure outcome with the error provided by the block.

Link copied to clipboard
inline fun <In, Out : Any, Error : Any> In.failureOf(block: (In) -> Error): Failure<Error>

Builds a Failure outcome with the error provided by the block.

Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.falter(transform: (Ok) -> Error): Failure<Error>

An alias for coerceToFailure.

Link copied to clipboard
inline fun <T : Any> T.faulty(isFailure: T.() -> Boolean): Faulty<T>

Wraps a value of type T as a Faulty based on a isFailure.

Link copied to clipboard
inline fun <Error : Any> faultyOf(catch: (throwable: Throwable) -> Faulty<Error> = ::rethrow, block: RaiseScope<Error>.() -> Unit): Faulty<Error>

Context runner that encapsulates the result of block as a Faulty.

Link copied to clipboard
inline fun <In, Error : Any> In.faultyOf(catch: (throwable: Throwable) -> Faulty<Error> = ::rethrow, block: RaiseScope<Error>.(In) -> Unit): Faulty<Error>

Context runner that encapsulates the result of block as a Faulty.

Link copied to clipboard
infix inline fun <Ok : Any, ErrorIn : Any, ErrorOut : Any> Outcome<Ok, ErrorIn>.flatMapFailure(transform: (ErrorIn) -> Outcome<Ok, ErrorOut>): Outcome<Ok, ErrorOut>

Returns a new Outcome, after applying transform to the Failure error.

Link copied to clipboard
infix inline fun <In : Any, Out : Any, Error : Any> Outcome<In, Error>.flatMapSuccess(transform: (In) -> Outcome<Out, Error>): Outcome<Out, Error>

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

Link copied to clipboard
Link copied to clipboard
inline fun <Ok : Any, Error : Any, Output> Outcome<Ok, Error>.fold(failure: Failure<Error>.() -> Output, success: Success<Ok>.() -> Output): Output

Fold the caller into some Output.

Link copied to clipboard
infix fun <Ok : Any, Error : Any> Outcome<Ok, Error>.getOrDefault(default: Ok): Ok
Link copied to clipboard
infix inline fun <Ok, Error : Any> Outcome<Ok & Any, Error>.getOrElse(recover: (Error) -> Ok): Ok
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Inverts the Outcome so that the Success value becomes the Failure error and vice versa.

Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.isFailure(predicate: (Error) -> Boolean): Boolean
Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.isSuccess(predicate: (Ok) -> Boolean): Boolean
Link copied to clipboard
inline fun <In : Any, Out : Any, ErrorIn : Any, ErrorOut : Any> Outcome<In, ErrorIn>.map(failure: (ErrorIn) -> ErrorOut, success: (In) -> Out): Outcome<Out, ErrorOut>

Transform an Outcome with either success or failure.

Link copied to clipboard
infix inline fun <Ok : Any, ErrorIn : Any, ErrorOut : Any> Outcome<Ok, ErrorIn>.mapFailure(transform: (ErrorIn) -> ErrorOut): Outcome<Ok, ErrorOut>

Returns a new Outcome, after applying transform to the Failure error.

Link copied to clipboard
infix inline fun <In : Any, Out : Any, Error : Any> Outcome<In, Error>.mapSuccess(transform: (In) -> Out): Outcome<Out, Error>

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

Link copied to clipboard
inline fun <Ok : Any> Ok.maybe(isSuccess: Ok.() -> Boolean): Maybe<Ok>

Wraps a value of type Ok as a Maybe based on a isSuccess.

Link copied to clipboard
inline fun <Ok : Any> maybeOf(catch: (throwable: Throwable) -> Maybe<Ok> = ::emptyFailure, block: RaiseScope<Unit>.() -> Ok): Maybe<Ok>

Context runner that encapsulates the result of block as a Maybe.

Link copied to clipboard
inline fun <In, Out : Any> In.maybeOf(catch: (throwable: Throwable) -> Maybe<Out> = ::rethrow, block: RaiseScope<Unit>.(In) -> Out): Maybe<Out>

Context runner that encapsulates the result of block as a Maybe.

Link copied to clipboard
inline fun <T : Any> nullableOf(block: RaiseScope<Unit>.() -> T): T?

Context runner that uses RaiseScope to safely capture raised or thrown errors, and unwraps either the successful Outcome or null.

Link copied to clipboard
inline fun <In, Out : Any> In.nullableOf(block: RaiseScope<Unit>.(In) -> Out): Out?

Context runner that uses RaiseScope to safely capture raised or thrown errors, and unwraps either the successful Outcome or null.

Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.onFailure(block: (Error) -> Unit): Outcome<Ok, Error>
Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.onSuccess(block: (Ok) -> Unit): Outcome<Ok, Error>
Link copied to clipboard
inline fun <Ok : Any> outcome(block: RaiseScope<String>.() -> Ok): Outcome<Ok, String>

An alias for outcomeOf that uses a String as the Error type.

Link copied to clipboard
inline fun <In, Out : Any> In.outcome(block: RaiseScope<String>.(In) -> Out): Outcome<Out, String>

An alias for outcomeOf that uses a String as the Error type.

fun <Ok : Any, Error : Any> Ok.outcome(predicate: Ok.() -> Boolean, faulter: Ok.() -> Error): Outcome<Ok, Error>

Wraps a value of type Ok as an Outcome based on a predicate.

Link copied to clipboard
inline fun <Ok : Any, Error : Any> outcomeOf(catch: (throwable: Throwable) -> Outcome<Ok, Error> = ::rethrow, block: RaiseScope<Error>.() -> Ok): Outcome<Ok, Error>

Context runner that encapsulates the Ok result of block as an Success, and any raised or caught errors as an Failure.

Link copied to clipboard
inline fun <In, Out : Any, Error : Any> In.outcomeOf(catch: (throwable: Throwable) -> Outcome<Out, Error> = ::rethrow, block: RaiseScope<Error>.(In) -> Out): Outcome<Out, Error>

Context runner that encapsulates the result of block as an Success, and any raised or caught errors as an Failure.

Link copied to clipboard
infix inline fun <Ok : Any, Error : Any> Outcome<Ok, Error>.recover(transform: (Error) -> Ok): Success<Ok>

An alias for coerceToSuccess.

Link copied to clipboard
inline fun <Ok : Any, Error : Any, Output> Outcome<Ok, Error>.rfold(success: Success<Ok>.() -> Output, failure: Failure<Error>.() -> Output): Output

Reverse fold is syntax-sugar that swaps the lambda argument order.

Link copied to clipboard
inline fun <T : Any> safely(crossinline fallback: (Any) -> T, block: RaiseScope<Unit>.() -> T): T

Context runner that uses RaiseScope to safely capture raised or thrown errors, and unwraps either the successful Outcome or the fallback, returning T.

Link copied to clipboard
inline fun <In, Out : Any> In.safely(crossinline fallback: (Any) -> Out, block: RaiseScope<Unit>.(In) -> Out): Out

Context runner that uses RaiseScope to safely capture raised or thrown errors, and unwraps either the successful Outcome or the fallback, returning Out.

Link copied to clipboard
inline fun <Ok : Any> successOf(block: () -> Ok): Success<Ok>

Builds a Success outcome with the value provided by the block.

Link copied to clipboard
inline fun <In, Out : Any> In.successOf(block: (In) -> Out): Success<Out>

Builds a Success outcome with the value provided by the block.

Link copied to clipboard
inline fun <Ok : Any, ErrorIn : Any, ErrorOut : Any> Outcome<Ok, ErrorIn>.tryRecover(catch: (throwable: Throwable) -> Outcome<Ok, ErrorOut> = ::rethrow, failure: RaiseScope<ErrorOut>.(ErrorIn) -> Ok): Outcome<Ok, ErrorOut>

Transform failure into success.