sippo-sdk / com.quobis.sippo.sipposdk.common / Either

Either

sealed class Either<out V, out E : Throwable>

An asynchronous result.

This class groups all the methods needed in order to manage an asynchronous result that can be successful (Success] or not (Failure).

Parameters

V - Type of the value in case of success.

E - Type of the error in case of failure. It has to extend Throwable.

Types

Failure

data class Failure<out E : Throwable> : Either<Nothing, E>

Failed result with error error.

Success

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

Successful result with value value.

Properties

isFailure

val isFailure: Boolean

True if the result is an error, false otherwise.

isSuccess

val isSuccess: Boolean

True if the result was successful, false otherwise.

Functions

error

abstract fun error(): E?

Returns the error associated. In case of Success, error will be null.

value

abstract fun value(): V?

Returns the value associated. In case of Failure, value will be null.

Extension Functions

flatMap

fun <V, U, E : Throwable> Either<V, E>.flatMap(f: (V) -> Either<U, E>): Either<U, E>

Converts the Either value according to f function.

flatMapError

fun <V, E : Throwable, X : Throwable> Either<V, E>.flatMapError(f: (E) -> Either<V, X>): Either<V, X>

Converts the Either error according to f function.

map

fun <V, U, E : Throwable> Either<V, E>.map(f: (V) -> U): Either<U, E>

Converts the Either value according to f function.

mapError

fun <V, E : Throwable, X : Throwable> Either<V, E>.mapError(f: (E) -> X): Either<V, X>

Converts the Either error according to f function.

onFailure

fun <V, E : Throwable> Either<V, E>.onFailure(f: (E) -> Unit): Unit

Calls the function f with a specific error when Either is failure.

onSuccess

fun <V, E : Throwable> Either<V, E>.onSuccess(f: (V) -> Unit): Unit

Calls the function f with a specific value when Either is successful.

Inheritors

Failure

data class Failure<out E : Throwable> : Either<Nothing, E>

Failed result with error error.

Success

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

Successful result with value value.