Package-level declarations

Types

Link copied to clipboard
sealed interface DataError

Root of the typed error hierarchy carried in Result.Failure. Split by source so callers can react differently to a network failure vs a local one. Apps extend this with their own arms (e.g. a Validation error) by implementing the interface.

Link copied to clipboard
typealias EmptyResult<E> = Result<Unit, E>

A Result carrying no success payload — for operations whose success is just "it worked".

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

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.