io.paymenthighway.sdk.util / Result

Result

sealed class Result<out V, out E>

Used to represent whether a sdk operation was successful or encountered an error

Parameters

V - Type of the value returned for a successful operation

E - Type of the error

Types

Failure

data class Failure<out E> : Result<Nothing, E>

Operation failed and returned an associated Exception

Success

data class Success<out V> : Result<V, Nothing>

Operation was successful and return a associated value of type V

Properties

isError

val isError: Boolean

Returns true if the result is a failure

isSuccess

val isSuccess: Boolean

Returns true if the result is a success

Functions

getErrorOrNull

fun getErrorOrNull(): E?

Returns the associated exception error of type E if operation encountered a failure, otherwise null

getOrThrow

fun getOrThrow(): V

Returns the associated value of type V if operation was successful, otherwise throws the failure exception

getValueOrNull

fun getValueOrNull(): V?

Returns the associated value of type V if operation was successful, otherwise null

Companion Object Functions

failure

fun <E> failure(error: E): Failure<E>

Helper to build a Failure operation

of

fun <V> of(function: () -> V): Result<V, Exception>

Result built from the result of the function

success

fun <V> success(value: V): Success<V>

Helper to build a Success operation

Inheritors

Failure

data class Failure<out E> : Result<Nothing, E>

Operation failed and returned an associated Exception

Success

data class Success<out V> : Result<V, Nothing>

Operation was successful and return a associated value of type V