Package fr.haan.resultat

Types

Link copied to clipboard
sealed class Resultat<out T>

A sealed class that encapsulates a successful outcome with a value of type T or a failure with an arbitrary Throwable exception, or a loading state

Functions

Link copied to clipboard
inline fun <R, T> Resultat<T>.fold(    onSuccess: (value: T) -> R,     onFailure: (exception: Throwable) -> R,     onLoading: () -> R): R

Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure. or the result of onLoading function if it is loading.

Link copied to clipboard
inline fun <R, T : R> Resultat<T>.getOrDefault(defaultValue: R): R

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

Link copied to clipboard
fun <R, T : R> Resultat<T>.getOrElse(onFailure: (exception: Throwable) -> R): R

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

Link copied to clipboard
fun <T> Resultat<T>.getOrThrow(): T

Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.

Link copied to clipboard
inline fun <R, T> Resultat<T>.map(transform: (value: T) -> R): Resultat<R>

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

Link copied to clipboard
inline fun <R, T> Resultat<T>.mapCatching(transform: (value: T) -> R): Resultat<R>

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

Link copied to clipboard
inline fun <T> Resultat<T>.onFailure(action: (exception: Throwable) -> Unit): Resultat<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure. Returns the original Resultat unchanged.

Link copied to clipboard
inline fun <T> Resultat<T>.onLoading(action: () -> Unit): Resultat<T>

Performs the given action on the encapsulated value if this instance represents success. Returns the original Resultat unchanged.

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

Performs the given action on the encapsulated value if this instance represents success. Returns the original Resultat unchanged.

Link copied to clipboard
inline fun <R, T : R> Resultat<T>.recover(recoverLoading: Boolean = false, transform: (exception: Throwable) -> R): Resultat<R>

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

Link copied to clipboard
inline fun <R, T : R> Resultat<T>.recoverCatching(recoverLoading: Boolean = false, transform: (exception: Throwable) -> R): Resultat<R>

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

Link copied to clipboard
inline fun <T, R> T.runCatchingL(block: T.() -> R): Resultat<R>

Calls the specified function block with this value as its receiver and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.

Link copied to clipboard
fun <T> Resultat<T>.toResult(): Result<T>?

Convert Resultat to Kotlin Result if Resultat is Resultat.Loading, null is returned

Link copied to clipboard
fun <T> Result<T>.toResultat(): Resultat<T>

Convert Kotlin Result to Resultat type