KthResult

sealed interface KthResult<T, E : KthException>

The base result class returned by all API methods used in parsing an expression or calculating a result. Can be either Success or Error.

Inheritors

Types

Link copied to clipboard
data class Error<T, E : KthException>(val error: E) : KthResult<T, E>

Result returned in case of Error.

Link copied to clipboard
data class Success<T, E : KthException>(val value: T) : KthResult<T, E>

Result returned in case of Success.

Functions

Link copied to clipboard
open fun onError(block: (E) -> Unit): KthResult<T, E>

Executes a block of code when the result is Error, otherwise does nothing.

Link copied to clipboard
open fun onSuccess(block: (T) -> Unit): KthResult<T, E>

Executes a block of code when the result is Success, otherwise does nothing.

Link copied to clipboard
open fun orElse(other: T): T

Returns the result value in case of Success, otherwise returns the other value.

Link copied to clipboard
open fun orElseGet(block: (E) -> T): T

Returns the result value in case of Success, otherwise returns the result of the block of code.

Link copied to clipboard
open fun orNull(): T?

Returns the result value in case of Success, otherwise returns null.

Link copied to clipboard
open fun orThrow(): T

Returns the result value in case of Success, otherwise throws an exception related to the error.