Result

sealed class Result<out SuccessType, out FailureType>

Class that represents either the Success outcome with a value of type SuccessType or Failure with a value of type FailureType.

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Represents a failed operation that resulted in a FailureType.

Link copied to clipboard

Represents a successful operation that resulted in a returned SuccessType.

Functions

Link copied to clipboard
inline fun <V, F, V2, F2> Result<V, F>.bimap(successMapper: (V) -> V2, failureMapper: (F) -> F2): Result<V2, F2>

Maps success value or failure.

Link copied to clipboard
abstract fun failure(): FailureType

Returns a failure value if the result is Failure.

Link copied to clipboard
inline fun <V, F, V2> Result<V, F>.flatMap(mapper: (V) -> Result<V2, F>): Result<V2, F>

Maps success value to a new Result or passes failure.

Link copied to clipboard
inline fun <V, F, R> Result<V, F>.fold(ifSuccess: (V) -> R, ifFailure: (F) -> R): R

Folds success or failure into a final value.

Link copied to clipboard
inline fun <V, F> Result<V, F>.ifFailure(ifFailure: (F) -> Unit): Result<V, F>

Performs provided operation if Result is failure.

Link copied to clipboard
inline fun <V, F> Result<V, F>.ifSuccess(ifSuccess: (V) -> Unit): Result<V, F>

Performs provided operation if Result is success.

Link copied to clipboard
abstract fun isFailure(): Boolean

Returns true if Result finished with failure.

Link copied to clipboard
abstract fun isSuccess(): Boolean

Returns true if Result finished successfully.

Link copied to clipboard
inline fun <V, F, V2> Result<V, F>.map(mapper: (V) -> V2): Result<V2, F>

Maps success value or passes failure.

Link copied to clipboard
inline fun <V, F, F2> Result<V, F>.mapFailure(mapper: (F) -> F2): Result<V, F2>

Maps failure or passes success value.

Link copied to clipboard
fun <L, R> Result<R, L>.toEither(): Either<L, R>

Converts Result to Either. Result.Failure will be converted to Either.Left and Result.Success will be converted to Either.Right.

Link copied to clipboard
abstract fun value(): SuccessType

Returns a value if the result is Success.

Link copied to clipboard
inline fun <V, F> Result<V, F>.valueOr(handler: (F) -> V): V

Returns success value or uses handler to map failure to value.