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

Constructors

Expected
Link copied to clipboard
open fun Expected(error: E, value: V)
Create an expected instance, one of the provided arguments must be null else the expected will be treated as a value.

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(errorFun: Expected.Transformer<E, R>, valueFun: Expected.Transformer<V, R>): R
Fold the expected to a common type.
getValueOrElse
Link copied to clipboard
open fun getValueOrElse(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(errorFun: Expected.Transformer<E, E1>, 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(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(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(action: Expected.Action<E>): Expected<E, V>
Execute an action if this expected is an error.
onValue
Link copied to clipboard
open fun onValue(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