Expected

open class Expected<E, V>

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

Parameters

<E>

The error type of expected

<V>

The value type of expected

Types

Action
Link copied to clipboard
interface Action<T>
Functional interface to run an action on expected types.
Transformer
Link copied to clipboard
interface Transformer<T, R>
Functional interface to transform expected types.

Functions

fold
Link copied to clipboard
open fun <R> fold(@NonNull errorFun: Expected.Transformer<E, R>, @NonNull valueFun: Expected.Transformer<V, R>): R
Fold the expected to a common type.
getValueOrElse
Link copied to clipboard
open fun getValueOrElse(@NonNull defaultFun: Expected.Transformer<E, V>): V
Retruns the value, if available, or produces a fallback with the provided function.
isError
Link copied to clipboard
open fun isError(): Boolean
Returns if the expected contains an error.
isValue
Link copied to clipboard
open fun isValue(): Boolean
Returns if the expected contains a value.
map
Link copied to clipboard
open fun <E1, V1> map(@NonNull errorFun: Expected.Transformer<E, E1>, @NonNull valueFun: Expected.Transformer<V, V1>): Expected<E1, V1>
Map both value or error to a new type.
mapError
Link copied to clipboard
open fun <E1> mapError(@NonNull errorFun: Expected.Transformer<E, E1>): Expected<E1, V>
Map error to a new type or return encapsulated value.
mapValue
Link copied to clipboard
open fun <V1> mapValue(@NonNull valueFun: Expected.Transformer<V, V1>): Expected<E, V1>
Map value to a new type or return the encapsulated error.
onError
Link copied to clipboard
open fun onError(@NonNull action: Expected.Action<E>): Expected<E, V>
Execute an action if this expected is an error.
onValue
Link copied to clipboard
open fun onValue(@NonNull action: Expected.Action<V>): Expected<E, V>
Execute an action if this expected is an error.

Properties

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