core / pragma /

Package pragma #

Types #

NameSummary

PragmaResult

sealed class PragmaResult<out TSuccess, out TFailure>

A discriminated union that encapsulates a successful outcome with a value of type TSuccess or a failure with of type TFailure. Similar to kotlin.Result, but with non-exception failures.

Functions #

NameSummary

andThen

inline fun <TNewSuccess, TNewFailure, TSuccess, TFailure : TNewFailure> PragmaResult<TSuccess, TFailure>.andThen(onSuccess: (TSuccess) -> PragmaResult<TNewSuccess, TNewFailure>): PragmaResult<TNewSuccess, TNewFailure>

Returns the encapsulated result of the given onSuccess function applied to the encapsulated TSuccess if this instance represents success or the original encapsulated value if it is failure.

failureOrElse

inline fun <TNewFailure, TSuccess, TFailure : TNewFailure> PragmaResult<TSuccess, TFailure>.failureOrElse(onFailure: (TSuccess) -> TFailure): TFailure

Returns the encapsulated value if this instance represents failure or the result of onFailure function for the encapsulated TSuccess if it is success.

getOrDefault

inline fun <TSuccess, TFailure> PragmaResult<TSuccess, TFailure>.getOrDefault(onFailure: () -> TSuccess): TSuccess

Returns the encapsulated value if this instance represents success or the defaultValue if it is failure.

getOrElse

inline fun <TNewSuccess, TSuccess : TNewSuccess, TFailure> PragmaResult<TSuccess, TFailure>.getOrElse(onFailure: (TFailure) -> TSuccess): TSuccess

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated TFailure if it is failure.

map

inline fun <TNewSuccess, TSuccess : TNewSuccess, TNewFailure, TFailure : TNewFailure> PragmaResult<TSuccess, TFailure>.map(transform: (TSuccess) -> TNewSuccess): PragmaResult<TNewSuccess, TNewFailure>

Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated TFailure value if it is failure.

recover

inline fun <TNewSuccess, TSuccess : TNewSuccess, TFailure> PragmaResult<TSuccess, TFailure>.recover(transform: (TFailure) -> TNewSuccess): TNewSuccess

Returns the encapsulated result of the given transform function applied to the encapsulated TFailure if this instance represents failure or the original encapsulated value if it is success.