Expected(androidJvm)

Expected is wrapper object around either a value or an error.

open class Expected(androidJvm)<E, V>

Parameters

<E>

< The error type of expected

<V>

< The value type of expected

Constructors

Expected
Link copied to clipboard

Create an expected instance, one of the provided arguments must be null else the expected will be treated as a value.

open fun Expected(error: E, value: V)

Types

Action
Link copied to clipboard

Functional interface to run an action on expected types.

interface Action<T>
Transformer
Link copied to clipboard

Functional interface to transform expected types.

interface Transformer<T, R>

Functions

fold
Link copied to clipboard

Fold the expected to a common type.

open fun <R> fold(errorFun: Expected.Transformer<E, R>, valueFun: Expected.Transformer<V, R>): R
getValueOrElse
Link copied to clipboard

Retruns the value, if available, or produces a fallback with the provided function.

open fun getValueOrElse(defaultFun: Expected.Transformer<E, V>): V
isError
Link copied to clipboard

Returns if the expected contains an error.

open fun isError(): Boolean
isValue
Link copied to clipboard

Returns if the expected contains a value.

open fun isValue(): Boolean
map
Link copied to clipboard

Map both value or error to a new type.

open fun <E1, V1> map(errorFun: Expected.Transformer<E, E1>, valueFun: Expected.Transformer<V, V1>): Expected<E1, V1>
mapError
Link copied to clipboard

Map error to a new type or return encapsulated value.

open fun <E1> mapError(errorFun: Expected.Transformer<E, E1>): Expected<E1, V>
mapValue
Link copied to clipboard

Map value to a new type or return the encapsulated error.

open fun <V1> mapValue(valueFun: Expected.Transformer<V, V1>): Expected<E, V1>
onError
Link copied to clipboard

Execute an action if this expected is an error.

open fun onError(action: Expected.Action<E>): Expected<E, V>
onValue
Link copied to clipboard

Execute an action if this expected is an error.

open fun onValue(action: Expected.Action<V>): Expected<E, V>

Properties

error
Link copied to clipboard
private val error: E
value
Link copied to clipboard
private val value: V