Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
inline class Result<out T> : Serializable
A discriminated union that encapsulates successful outcome with a value of type T or a failure with an arbitrary Throwable exception.
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Returns the encapsulated exception if this instance represents failure or null
if it is success.
fun exceptionOrNull(): Throwable?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Returns the encapsulated value if this instance represents success or null
if it is failure.
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Returns a string Success(v)
if this instance represents success where v
is a string representation of the value or a string Failure(x)
if it is failure where x
is a string representation of the exception.
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the the result of onSuccess for encapsulated value if this instance represents success or the result of onFailure function for encapsulated exception if it is failure.
fun <R, T> Result<T>.fold(
onSuccess: (value: T) -> R,
onFailure: (exception: Throwable) -> R
): R
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated value if this instance represents success or the defaultValue if it is failure.
fun <R, T : R> Result<T>.getOrDefault(defaultValue: R): R
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated value if this instance represents success or the result of onFailure function for encapsulated exception if it is failure.
fun <R, T : R> Result<T>.getOrElse(
onFailure: (exception: Throwable) -> R
): R
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated value if this instance represents success or throws the encapsulated exception if it is failure.
fun <T> Result<T>.getOrThrow(): T
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated result of the given transform function applied to encapsulated value if this instance represents success or the original encapsulated exception if it is failure.
fun <R, T> Result<T>.map(
transform: (value: T) -> R
): Result<R>
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated result of the given transform function applied to encapsulated value if this instance represents success or the original encapsulated exception if it is failure.
fun <R, T> Result<T>.mapCatching(
transform: (value: T) -> R
): Result<R>
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Performs the given action on encapsulated exception if this instance represents failure. Returns the original Result
unchanged.
fun <T> Result<T>.onFailure(
action: (exception: Throwable) -> Unit
): Result<T>
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Performs the given action on encapsulated value if this instance represents success. Returns the original Result
unchanged.
fun <T> Result<T>.onSuccess(
action: (value: T) -> Unit
): Result<T>
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated result of the given transform function applied to encapsulated exception if this instance represents failure or the original encapsulated value if it is success.
fun <R, T : R> Result<T>.recover(
transform: (exception: Throwable) -> R
): Result<R>
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns the encapsulated result of the given transform function applied to encapsulated exception if this instance represents failure or the original encapsulated value if it is success.
fun <R, T : R> Result<T>.recoverCatching(
transform: (exception: Throwable) -> R
): Result<R>