Err

data class Err<E>(val error: E) : Result<Nothing, E>

The operation failed.

Constructors

Link copied to clipboard
constructor(error: E)

Properties

Link copied to clipboard
val error: E

The error returned by the operation.

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: Nothing?

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: (Nothing) -> 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<Nothing, 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(): Nothing

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