Ok

data class Ok<V>(val value: V) : Result<V, Nothing>

The operation completed successfully.

Constructors

Link copied to clipboard
constructor(value: V)

Properties

Link copied to clipboard
open val errorOrNull: Nothing?

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
val value: V

The return value of the operation.

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, Nothing>

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

Link copied to clipboard
open fun <E2> mapError(filter: (Nothing) -> 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.