Result

sealed interface Result<out D, out E>

A typed success-or-failure. Unlike kotlin.Result, the error arm is a typed E (usually a DataError) rather than a Throwable, so callers exhaustively handle known failure modes instead of catching. Import this Result explicitly where kotlin.Result is also in scope.

Inheritors

Types

Link copied to clipboard
data class Failure<out E>(val error: E) : Result<Nothing, E>
Link copied to clipboard
data class Success<out D>(val data: D) : Result<D, Nothing>

Functions

Link copied to clipboard
fun <D, E> Result<D, E>.asEmpty(): EmptyResult<E>

Discard the success payload, keeping only success-vs-failure.

Link copied to clipboard
fun <D, E> Result<D, E>.errorOrNull(): E?
Link copied to clipboard
inline fun <D, E, R> Result<D, E>.flatMap(transform: (D) -> Result<R, E>): Result<R, E>

Chain a success into another Result; failures short-circuit.

Link copied to clipboard
inline fun <D, E, R> Result<D, E>.fold(onSuccess: (D) -> R, onFailure: (E) -> R): R

Collapse both arms into one value.

Link copied to clipboard
fun <D, E> Result<D, E>.getOrNull(): D?
Link copied to clipboard
inline fun <D, E, R> Result<D, E>.map(transform: (D) -> R): Result<R, E>

Map the success value; failures pass through untouched.

Link copied to clipboard
inline fun <D, E, F> Result<D, E>.mapError(transform: (E) -> F): Result<D, F>

Map the error arm; successes pass through untouched.

Link copied to clipboard
inline fun <D, E> Result<D, E>.onFailure(action: (E) -> Unit): Result<D, E>

Run action on failure, returning the receiver for chaining.

Link copied to clipboard
inline fun <D, E> Result<D, E>.onSuccess(action: (D) -> Unit): Result<D, E>

Run action on success, returning the receiver for chaining.