Result

sealed class Result<out V, out E>

Result is a type that represents either success (Ok) or failure (Err).

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract operator fun component1(): V?
Link copied to clipboard
abstract operator fun component2(): E?

Inheritors

Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
infix fun <V, E> Result<V, E>.and(result: Result<V, E>): Result<V, E>

Returns result if this Result is Ok, otherwise this Err.

infix inline fun <V, E> Result<V, E>.and(result: () -> Result<V, E>): Result<V, E>
Link copied to clipboard
infix inline fun <V, E, U> Result<V, E>.andThen(transform: (V) -> Result<U, E>): Result<U, E>

Maps this Result to Result by either applying the transform function if this Result is Ok, or returning this Err.

Link copied to clipboard
infix fun <V, E> Result<V, E>.expect(message: String): V

infix inline fun <V, E> Result<V, E>.expect(message: () -> Any): V

Unwraps a Result, yielding the value.

Link copied to clipboard
infix fun <V, E> Result<V, E>.expectError(message: String): E

infix inline fun <V, E> Result<V, E>.expectError(message: () -> Any): E

Unwraps a Result, yielding the error.

Link copied to clipboard
infix inline fun <V, E, U> Result<V, E>.flatMap(transform: (V) -> Result<U, E>): Result<U, E>

Maps this Result to Result by either applying the transform function if this Result is Ok, or returning this Err.

Link copied to clipboard
inline fun <V, E, U> Result<V, E>.fold(success: (V) -> U, failure: (E) -> U): U

Maps this Result to U by applying either the success function if this Result is Ok, or the failure function if this Result is an Err. Both of these functions must return the same type (U).

Link copied to clipboard
fun <V, E> Result<V, E>.get(): V?

Returns the value if this Result is Ok, otherwise null.

Link copied to clipboard
fun <V, E> Result<V, E>.getError(): E?

Returns the error if this Result is Err, otherwise null.

Link copied to clipboard
infix fun <V, E> Result<V, E>.getErrorOr(default: E): E

Returns the error if this Result is Err, otherwise default.

infix inline fun <V, E> Result<V, E>.getErrorOr(default: () -> E): E
Link copied to clipboard
infix inline fun <V, E> Result<V, E>.getErrorOrElse(transform: (V) -> E): E

Returns the error if this Result is Err, otherwise the transformation of the value.

Link copied to clipboard
infix fun <V, E> Result<V, E>.getOr(default: V): V

Returns the value if this Result is Ok, otherwise default.

infix inline fun <V, E> Result<V, E>.getOr(default: () -> V): V
Link copied to clipboard
infix inline fun <V, E> Result<V, E>.getOrElse(transform: (E) -> V): V

Returns the value if this Result is Ok, otherwise the transformation of the error.

Link copied to clipboard
fun <V, E : Throwable> Result<V, E>.getOrThrow(): V

Returns the value if this Result is Ok, otherwise throws the error.

infix inline fun <V, E> Result<V, E>.getOrThrow(transform: (E) -> Throwable): V

Returns the value if this Result is Ok, otherwise throws the transformation of the error to a Throwable.

Link copied to clipboard
fun <V, E> Result<V, E>.iterator(): Iterator<V>

Returns an Iterator over the possibly contained value. The iterator yields one value if the Result is Ok, otherwise throws NoSuchElementException.

Link copied to clipboard
infix inline fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E>

Maps this Result to Result by either applying the transform function to the value if this Result is Ok, or returning this Err.

Link copied to clipboard
infix inline fun <V, E, U> Result<Iterable<V>, E>.mapAll(transform: (V) -> Result<U, E>): Result<List<U>, E>

Returns a Result, E> containing the results of applying the given transform function to each element in the original collection, returning early with the first Err if a transformation fails.

Link copied to clipboard
inline fun <V, E, U> Result<V, E>.mapBoth(success: (V) -> U, failure: (E) -> U): U

Maps this Result to U by applying either the success function if this Result is Ok, or the failure function if this Result is an Err. Both of these functions must return the same type (U).

Link copied to clipboard
inline fun <V, E, U, F> Result<V, E>.mapEither(success: (V) -> U, failure: (E) -> F): Result<U, F>

Maps this Result to Result by applying either the success function if this Result is Ok, or the failure function if this Result is an Err.

Link copied to clipboard
infix inline fun <V, E, F> Result<V, E>.mapError(transform: (E) -> F): Result<V, F>

Maps this Result to Result by either applying the transform function to the error if this Result is Err, or returning this Ok.

Link copied to clipboard
inline fun <V, E, U> Result<V, E>.mapOr(default: U, transform: (V) -> U): U

Maps this Result to U by either applying the transform function to the value if this Result is Ok, or returning the default if this Result is an Err.

Link copied to clipboard
inline fun <V, E, U> Result<V, E>.mapOrElse(default: (E) -> U, transform: (V) -> U): U

Maps this Result to U by applying either the transform function if this Result is Ok, or the default function if this Result is an Err. Both of these functions must return the same type (U).

Link copied to clipboard
fun <V : U, E : U, U> Result<V, E>.merge(): U

Merges this Result to U, returning the value if this Result is Ok, otherwise the error.

Link copied to clipboard
fun <V, E> Result<V, E>.mutableIterator(): MutableIterator<V>

Returns a MutableIterator over the possibly contained value. The iterator yields one value if the Result is Ok, otherwise throws NoSuchElementException.

Link copied to clipboard
infix inline fun <V, E> Result<V, E>.onFailure(action: (E) -> Unit): Result<V, E>

Invokes an action if this Result is Err.

Link copied to clipboard
infix inline fun <V, E> Result<V, E>.onSuccess(action: (V) -> Unit): Result<V, E>

Invokes an action if this Result is Ok.

Link copied to clipboard
infix fun <V, E> Result<V, E>.or(result: Result<V, E>): Result<V, E>

Returns result if this Result is Err, otherwise this Ok.

infix inline fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E>
Link copied to clipboard
infix inline fun <V, E> Result<V, E>.orElse(transform: (E) -> Result<V, E>): Result<V, E>

Returns the transformation of the error if this Result is Err, otherwise this Ok.

Link copied to clipboard
fun <V, E : Throwable> Result<V, E>.orElseThrow(): Ok<V>

Throws the error if this Result is Err, otherwise returns this Ok.

Link copied to clipboard
infix inline fun <V, E> Result<V, E>.recover(transform: (E) -> V): Ok<V>

Returns the transformation of the error if this Result is Err, otherwise this Ok.

Link copied to clipboard
inline fun <V, E> Result<V, E>.recoverIf(predicate: (E) -> Boolean, transform: (E) -> V): Result<V, E>

Returns the transformation of the error if this Result is Err and satisfies the given predicate, otherwise this Result.

Link copied to clipboard
inline fun <V, E> Result<V, E>.recoverUnless(predicate: (E) -> Boolean, transform: (E) -> V): Result<V, E>

Returns the transformation of the error if this Result is Err and does not satisfy the given predicate, otherwise this Result.

Link copied to clipboard
inline fun <V, E : Throwable> Result<V, E>.throwIf(predicate: (E) -> Boolean): Result<V, E>

Throws the error if this Result is an Err and satisfies the given predicate, otherwise returns this Result.

Link copied to clipboard
inline fun <V, E : Throwable> Result<V, E>.throwUnless(predicate: (E) -> Boolean): Result<V, E>

Throws the error if this Result is an Err and does not satisfy the given predicate, otherwise returns this Result.

Link copied to clipboard
inline fun <V, E> Result<V, E>.toErrorIf(predicate: (V) -> Boolean, transform: (V) -> E): Result<V, E>

Returns the transformation of the value if this Result is Ok and satisfies the given predicate, otherwise this Result.

Link copied to clipboard
inline fun <V, E> Result<V, E>.toErrorUnless(predicate: (V) -> Boolean, transform: (V) -> E): Result<V, E>

Returns the transformation of the value if this Result is Ok and does not satisfy the given predicate, otherwise this Result.

Link copied to clipboard
fun <V, E> Result<V, E>.unwrap(): V

Unwraps a Result, yielding the value.

Link copied to clipboard
fun <V, E> Result<V, E>.unwrapError(): E

Unwraps a Result, yielding the error.