Success

data class Success<out T>(val data: T) : UiState<T>

Indicates successful completion holding the resulting data.

Parameters

data

The payload produced by the successful operation.

Constructors

Link copied to clipboard
constructor(data: T)

Properties

Link copied to clipboard
val data: T
Link copied to clipboard
open val isFailure: Boolean
Link copied to clipboard
open val isIdle: Boolean
Link copied to clipboard
open val isLoading: Boolean
Link copied to clipboard
open val isSuccess: Boolean

Functions

Link copied to clipboard
inline fun <T> UiState<T>.Content(crossinline onSuccess: @Composable (data: T) -> Unit, noinline onLoading: @Composable () -> Unit? = null, noinline onIdle: @Composable () -> Unit? = null, noinline onFailure: @Composable (throwable: Throwable) -> Unit? = null)

Exhaustively renders UI content based on the current UiState.

Link copied to clipboard

Returns the encapsulated throwable if this state is UiState.Failure, or null otherwise.

Link copied to clipboard
inline fun <T, R> UiState<T>.flatMap(transform: (T) -> UiState<R>): UiState<R>

Transforms the UiState.Success data using the given transform function that returns a new UiState.

Link copied to clipboard
inline fun <T, R> UiState<T>.fold(onSuccess: (data: T) -> R, onFailure: (throwable: Throwable) -> R, onLoading: () -> R, onIdle: () -> R): R
Link copied to clipboard
fun <T> UiState<T>.getOrDefault(default: T): T

Returns the encapsulated data if this state is UiState.Success, or default otherwise.

Link copied to clipboard
inline fun <T> UiState<T>.getOrElse(onFailure: (throwable: Throwable?) -> T): T

Returns the encapsulated data if this state is UiState.Success, or the result of onFailure function for non-success states.

Link copied to clipboard
fun <T> UiState<T>.getOrNull(): T?

Returns the encapsulated data if this state is UiState.Success, or null otherwise.

Link copied to clipboard
fun <T> UiState<T>.getOrThrow(): T

Returns the encapsulated data if this state is UiState.Success, or throws the encapsulated Throwable if this state is UiState.Failure, or an IllegalStateException if UiState.Idle or UiState.Loading.

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

Transforms the UiState.Success data using the given transform function. Non-success states (UiState.Idle, UiState.Loading, UiState.Failure) are passed through unchanged.

Link copied to clipboard
inline fun <T> UiState<T>.onFailure(block: (throwable: Throwable) -> Unit): UiState<T>

Executes block with UiState.Failure.throwable if the UiState is UiState.Failure. Returns this to allow chaining.

Link copied to clipboard
inline fun <T> UiState<T>.onIdle(block: () -> Unit): UiState<T>

Executes block if the UiState is UiState.Idle. Returns this to allow chaining.

Link copied to clipboard
inline fun <T> UiState<T>.onLoading(block: () -> Unit): UiState<T>

Executes block if the UiState is UiState.Loading. Returns this to allow chaining.

Link copied to clipboard
inline fun <T> UiState<T>.onSuccess(block: (data: T) -> Unit): UiState<T>

Executes block with UiState.Success.data if the UiState is UiState.Success. Returns this to allow chaining.