ResultChain<T, E> extension

Chaining and extraction on Result.

An extension rather than members of Result, so the types come from the static type at the call site. As members they were checked against the type a value was built with, and an Ok<int, NotFound> held in a Result<int, AppError> threw a TypeError when chained with a step that fails with another AppError.

on

Methods

andThen<R>(Result<R, E> next(T value)) → Result<R, E>

Available on Result<T, E>, provided by the ResultChain extension

Chains another result-producing operation when this result is successful.
orElse<F>(Result<T, F> next(E error)) → Result<T, F>

Available on Result<T, E>, provided by the ResultChain extension

Chains another result-producing operation when this result failed.
unwrapOr(T fallback) → T

Available on Result<T, E>, provided by the ResultChain extension

Returns the successful value, or fallback when this result failed.
unwrapOrElse(T fallback(E error)) → T

Available on Result<T, E>, provided by the ResultChain extension

Returns the successful value, or computes one from the error.