getOrElse

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

Returns the carried value, or what onFailure makes of the failure.

onFailure receives the whole DataResult.Failure rather than the exception inside it, so it can be returned as it stands - which is what makes the early exit out of a transaction block read the way it does:

val id = insertCitizen().getOrElse { return@transaction it }

Return

The value on success, or the result of onFailure.

Parameters

onFailure

What to produce from a failure.