Result

sealed interface Result<out V, out E>

The result of an operation: either Result.Ok or Result.Err.

Inheritors

Types

Link copied to clipboard
data class Err<E>(val error: E) : Result<Nothing, E>

The operation failed.

Link copied to clipboard
data class Ok<V>(val value: V) : Result<V, Nothing>

The operation completed successfully.

Properties

Link copied to clipboard
open val errorOrNull: E?

If the operation failed, this is the error. Otherwise this is null.

Link copied to clipboard
open val ok: Boolean

Returns true if the operation succeeded, or false if there was an error.

Link copied to clipboard
open val valueOrNull: V?

If the operation was successful, this is the return value. Otherwise this is null.

Functions

Link copied to clipboard
inline fun <V, E> Result<V, E>.ifError(onError: (E) -> Unit)

Kotlin convenience method: invoke the callback if the result is an error.

Link copied to clipboard
open fun <V2> map(filter: (V) -> V2): Result<V2, E>

If the result is a success, this method transforms the value to a different type.

Link copied to clipboard
open fun <E2> mapError(filter: (E) -> E2): Result<V, E2>

If the result is an error, this method transforms the error to a different type.

Link copied to clipboard
inline fun <V, E> Result<V, E>.orError(onError: (E) -> Nothing): V

Kotlin convenience method: return the value if Ok, otherwise invoke the callback with the error.

Link copied to clipboard
open fun throwError(): V

If the operation failed, throw a VoiceException, otherwise return the result.