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

Link copied to clipboard
Functional interface to run an action on expected types.
Link copied to clipboard
Functional interface to transform expected types.

Functions

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

Properties

Link copied to clipboard
@Nullable
@get:Nullable
val error: E
Link copied to clipboard
@Nullable
@get:Nullable
val value: V