Failure

data class Failure<out E : Exception>(val reason: E) : Result<Nothing, E>

Constructors

Link copied to clipboard
constructor(reason: E)

Properties

Link copied to clipboard
val reason: E

Functions

Link copied to clipboard
infix inline fun <R, E : Exception, R2, E2 : Exception> Result<R2, E2>.failWith(block: (E2) -> E): R2

Return the value of the success case or fail with the exception returned from the "block" block.

Link copied to clipboard
fun <R, E : Exception> Result<R, E>.getOrNull(): R?

Return the value of the success case or null.

Link copied to clipboard
fun <R, E : Exception> Result<R, E>.getOrThrow(): R

Return the value of the success case or throws the exception.

Link copied to clipboard
inline fun <R, E : Exception, T> Result<R, E>.map(transform: (R) -> T): Result<T, E>

Creates a new Result with the value mapped to a new type.

Link copied to clipboard
inline fun <R, E : Exception, T : Exception> Result<R, E>.mapFailure(transform: (E) -> T): Result<R, T>

Creates a new Result with the exception mapped to a new type.

Link copied to clipboard
infix inline fun <R, E : Exception> Result<R, E>.onFailure(block: (E) -> Unit): Result<R, E>

Calls block if the result is a Failure.

Link copied to clipboard
inline fun <R, E : Exception> Result<R, E>.recover(transform: (E) -> R?): Result<R, E>

Provides a way to recover from a failure. The transform block is only called if the result is a Failure.