Package-level declarations

Types

Link copied to clipboard
data class DataPayload<out T> : HubPayload<T>

Encapsulates a successful outcome with a value of type T.

Link copied to clipboard

Encapsulates an error outcome with a message and an errorCode.

Link copied to clipboard
object HubApi
Link copied to clipboard
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.

Link copied to clipboard

Marks declarations that are internal in SDK-Hub API, which means that should not be used outside of imahub.sdk.hub, because their signatures and semantics will change between future releases without any warnings and without providing any migration aids.

Functions

Link copied to clipboard
inline fun <T : Any> dataPayload(data: T): DataPayload<T>

Creates an instance of DataPayload.

Link copied to clipboard
fun errorPayload(message: String, code: Int): ErrorPayload

Creates an instance of ErrorPayload.

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

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.