Failure

data class Failure(val message: String, val throwable: Throwable? = null, val outcome: Outcome<*>? = null) : Outcome<Nothing>

Represents a failed outcome with an error message and optional cause.

Parameters

message

A description of the failure.

throwable

An optional Throwable that caused the failure.

outcome

An optional nested Outcome for chained failures.

Constructors

Link copied to clipboard
constructor(message: String, throwable: Throwable? = null, outcome: Outcome<*>? = null)

Properties

Link copied to clipboard
open val failed: Boolean

Indicates whether the operation failed (opposite of succeeded).

Link copied to clipboard
Link copied to clipboard
val outcome: Outcome<*>?
Link copied to clipboard
open override val succeeded: Boolean

Indicates whether the operation succeeded.

Link copied to clipboard

Functions

Link copied to clipboard

Returns the Throwable of a Failure or null if the outcome is a Success.

Link copied to clipboard
inline suspend fun <T, R> Outcome<T>.flatMap(transform: suspend (T) -> Outcome<R>): Outcome<R>

Flat-maps the value of a successful Outcome using the provided transform function.

Link copied to clipboard
inline suspend fun <T, R> Outcome<T>.fold(onSuccess: suspend (T) -> R, onFailure: suspend (String, Throwable?) -> R): R

Folds the Outcome into a single value by applying onSuccess for a Success or onFailure for a Failure.

Link copied to clipboard
open fun getOrNull(): Nothing?

Returns the value of a Success or null if the outcome is a Failure.

Link copied to clipboard
inline suspend fun <T, R> Outcome<T>.map(transform: suspend (T) -> R): Outcome<R>

Maps the value of a successful Outcome using the provided transform function.

Link copied to clipboard
inline suspend fun <T, R> Outcome<T>.mapCatching(transform: suspend (T) -> R): Outcome<R>

Maps the value of a successful Outcome using the provided transform function, catching any exceptions.

Link copied to clipboard
inline suspend fun <T> Outcome<T>.mapFailure(transform: suspend (Outcome.Failure) -> Outcome.Failure): Outcome<T>

Maps a Failure using the provided transform function, leaving Success unchanged.

Link copied to clipboard
inline suspend fun <T> Outcome<T>.recover(recoverBlock: suspend (Outcome.Failure) -> T): Outcome<T>

Recovers from a Failure by applying the recoverBlock function to produce a new value.

Link copied to clipboard
inline suspend fun <T> Outcome<T>.recoverCatching(recoverBlock: suspend (Outcome.Failure) -> T): Outcome<T>

Recovers from a Failure by applying the recoverBlock function, catching any exceptions.

Link copied to clipboard
open fun toResult(): Result<Nothing>

Converts this Outcome to a Result.

Link copied to clipboard
open override fun toString(): String

Returns a string representation of this Failure instance.

Link copied to clipboard

Returns a string representation of this Failure instance with stack trace details.