Package: effect
Module: Result
Extracts the success value, or computes a fallback from the error.
When to use
Use when you need the success value from a Result, with a fallback computed
from the failure value.
Details
Success<A> returns the inner valueFailure<E> applies onFailure to the error and returns the resultA | A2 (union of both branches)Example (Providing a fallback)
import { Result } from "effect"
console.log(Result.getOrElse(Result.succeed(1), () => 0))
// Output: 1
console.log(Result.getOrElse(Result.fail("err"), () => 0))
// Output: 0
See
getOrNull / getOrUndefined for simpler fallbacksgetOrThrow to throw on failurematch to map both branchesorElse to recover with another Result instead of unwrappingSignature
declare const getOrElse: { <E, A2>(onFailure: (err: E) => A2): <A>(self: Result<A, E>) => A2 | A; <A, E, A2>(self: Result<A, E>, onFailure: (err: E) => A2): A | A2; }
Since v2.0.0