getOrElse

inline fun <R, T : R> DataResult<T>.getOrElse(onFailure: (DataResult.Failure) -> R): R

Returns the encapsulated value if this instance represents Success or the result of onFailure function for the encapsulated Failure if it is failure.

This allows for a safe "exit" from the DataResult container by providing a fallback value or performing a non-local return (e.g., in a transaction block).

Examples:

val data = result.getOrElse { emptyList() }
//...
val value = result.getOrElse { return it } // Early return the failure

Return

The value of type T or the result of onFailure.

Parameters

onFailure

A function that receives the Failure and returns a value of type R.

Type Parameters

R

The result type.

T

The type of the value in Success.