SolidResult

sealed class SolidResult<out T>

The result of every library operation: either a Success carrying the value, or a Failure carrying a typed SolidError.

This is the one result shape across the whole library, replacing the former mix of per-feature result types, thrown exceptions, nullable returns, and Success(empty)-on-failure. Because failure is a typed SolidError — not a status int or a prose string — callers branch on SolidError.code and never string-parse an error.

Prefer the combinators (map, flatMap, fold, recover) and the accessors (getOrNull, errorOrNull, getOrThrow) over a manual when.

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class Failure(val error: SolidError) : SolidResult<Nothing>
Link copied to clipboard
data class Success<out T>(val value: T) : SolidResult<T>

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

The error, or null on success.

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

Chains an operation that itself returns a SolidResult, propagating a failure unchanged.

Link copied to clipboard
inline fun <R> fold(onSuccess: (T) -> R, onFailure: (SolidError) -> R): R

Collapses both variants to a single R.

Link copied to clipboard
fun getOrDefault(default: T): T

The success value, or default on failure.

Link copied to clipboard
inline fun getOrElse(onFailure: (SolidError) -> T): T

The success value, or the result of onFailure applied to the error.

Link copied to clipboard
fun getOrNull(): T?

The success value, or null on failure.

Link copied to clipboard
fun getOrThrow(): T

The success value, or throws SolidResultException carrying the error (and its cause).

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

Transforms the success value, propagating a failure unchanged.

Link copied to clipboard
inline fun onFailure(action: (SolidError) -> Unit): SolidResult<T>

Runs action on the error and returns this result unchanged.

Link copied to clipboard
inline fun onSuccess(action: (T) -> Unit): SolidResult<T>

Runs action on the success value and returns this result unchanged.

Link copied to clipboard
inline fun recover(transform: (SolidError) -> T): SolidResult<T>

Recovers a failure to a success value; a success passes through unchanged.