Failure

class Failure<out E>(val error: E) : KResult<E, Nothing> , KResult.HasError<E> (source)

Represents a failed KResult

Constructors

Link copied to clipboard
constructor(error: E)

Properties

Link copied to clipboard
open override val error: E

Functions

Link copied to clipboard

Transforms a KResult to a Kotlin native kotlin.Result

Link copied to clipboard
fun <E, T> KResult<E, T>.combine(other: KResult<E, T>, combineFailure: (E, E) -> E, combineSuccess: (T, T) -> T): KResult<E, T>
Link copied to clipboard
operator fun <E : Comparable<E>, T : Comparable<T>> KResult<E, T>.compareTo(other: KResult<E, T>): Int
Link copied to clipboard
open operator fun component1(): E?

Failure component for destructuring declaration

Link copied to clipboard
open operator fun component2(): Nothing?

Success component for destructuring declaration

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Returns a list of errors

Link copied to clipboard
infix inline fun <E, T> KResult<E, T>.failureOrDefault(default: (T) -> E): E

Returns the error of the Failure side, or the result of the default function otherwise

Link copied to clipboard

Runs the Failure.error, if the KResult is a failure or null otherwise

Link copied to clipboard
inline fun <E, T> KResult<E, T>.filter(failureValue: E, f: (success: T) -> Boolean): KResult<E, T>
inline fun <E, T> KResult<E, T>.filter(failureFn: (success: T) -> E, f: (success: T) -> Boolean): KResult<E, T>
Link copied to clipboard
inline fun <E, T, T1> KResult<E, T>.flatMap(f: (success: T) -> KResult<E, T1>): KResult<E, T1>
Link copied to clipboard
fun <E, T, E1> KResult<E, T>.flatMapFailure(f: (failure: E) -> KResult<E1, T>): KResult<E1, T>
Link copied to clipboard
fun <E, T> KResult<E, KResult<E, T>>.flatten(): KResult<E, T>
Link copied to clipboard
Link copied to clipboard
inline fun <R> fold(ifFailure: (failure: E) -> R, ifSuccess: (success: Nothing) -> R): R

Transforms a KResult into a value of R.

Link copied to clipboard
infix inline fun <E, T> KResult<E, T>.getOrDefault(default: (E) -> T): T

Returns the value of the Success side, or the result of the default function otherwise

Link copied to clipboard
infix inline fun <E, T> KResult<E, T>.getOrElse(default: (E) -> T): T
Link copied to clipboard

Runs the Success.value, if the KResult is a success or null otherwise

Link copied to clipboard
fun <E : Throwable, T> KResult<E, T>.getOrThrow(): T

If a KResult has a Throwable on failure side, this either returns the Success.value or throws the Failure.error

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Indicates if a KResult is a Failure

Link copied to clipboard

Indicates if a KResult is a Success

Link copied to clipboard
inline fun <R> map(f: (success: Nothing) -> R): KResult<E, R>

Maps (transforms) the success value T to a new value R

Link copied to clipboard
inline fun <R> mapFailure(f: (E) -> R): KResult<R, Nothing>

Maps (transforms) the failure value E to a new value R

Link copied to clipboard
fun <T> KResult<T, T>.merge(): T
Link copied to clipboard
inline fun onFailure(action: (failure: E) -> Unit): KResult<E, Nothing>

Runs an action (side-effect) when the KResult is a Failure

Link copied to clipboard
inline fun onSuccess(action: (success: Nothing) -> Unit): KResult<E, Nothing>

Runs an action (side-effect) when the KResult is a Success

Link copied to clipboard

Swap the parameters (T and E) of this Result.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
inline fun <E, T> MultiErrorKResult<E, T>.validate(failureValue: E, expectationFn: (success: T) -> Boolean): MultiErrorKResult<E, T>

Validates a Success or a FailureWithValue against a predicate (expectationFn] and applies failureValue if not fulfilled

Link copied to clipboard

Extends an existing Failure with a value to produce a FailureWithValue