HubPayload

sealed class HubPayload<out T>

A discriminated union that encapsulates a successful outcome with a value of DataPayload of type T or a failure with type ErrorPayload.

This union is used mainly on hub's server RSocket APIs.

Inheritors

Functions

Link copied to clipboard

Returns the encapsulated ErrorPayload if this instance represents failure or null if it is success.

Link copied to clipboard
inline fun <T, R> HubPayload<T>.fold(onSuccess: (value: T) -> R, onFailure: (error: ErrorPayload) -> R): R

Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated ErrorPayload if it is failure.

Link copied to clipboard
inline fun <T : R, R> HubPayload<T>.getOrElse(onFailure: (error: ErrorPayload) -> R): R

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated ErrorPayload if it is failure.

Link copied to clipboard
fun getOrNull(): T?

Returns the encapsulated value if this instance represents success or null if it is failure.

Link copied to clipboard

Returns the encapsulated value if this instance represents success or throws the encapsulated ErrorPayload as Throwable exception if it is failure.

Link copied to clipboard
inline fun <T, R : Any> HubPayload<T>.map(transform: (T) -> R): HubPayload<R>

Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated ErrorPayload if it is failure.

Link copied to clipboard
inline fun <T> HubPayload<T>.onFailure(action: (error: ErrorPayload) -> Unit): HubPayload<T>

Performs the given action on the encapsulated ErrorPayload if this instance represents failure. Returns the original HubPayload unchanged.

Link copied to clipboard
inline fun <T> HubPayload<T>.onSuccess(action: (value: T) -> Unit): HubPayload<T>

Performs the given action on the encapsulated value if this instance represents success. Returns the original HubPayload unchanged.