Result

sealed class Result<out R>

Represents an asynchronous operation that can be in one of four states: loading, success, error, or empty.

Type Parameters

R

The type of data held by a successful result.

Inheritors

Constructors

Link copied to clipboard
protected constructor()

Types

Link copied to clipboard
object Empty : Result<Nothing>

The operation completed but produced no meaningful data.

Link copied to clipboard
data class Error(val exception: Exception) : Result<Nothing>

The operation failed with an exception describing the cause.

Link copied to clipboard

The operation is currently in progress and has not yet produced a value.

Link copied to clipboard
data class Success<out T>(val data: T) : Result<T>

The operation completed successfully with data.

Properties

Link copied to clipboard
val <T> Result<T>.data: T?

Extracts the data from a Result.Success, or returns null for all other states.

Functions

Link copied to clipboard
fun <T, R> Result<T>.map(block: (T) -> Result<R>): Result<R>

Transforms a successful result using block, propagating Result.Loading, Result.Empty, and Result.Error unchanged.

Link copied to clipboard
open override fun toString(): String