Package: effect
Module: Option
Extracts the value from a Some, or evaluates a fallback thunk on None.
When to use
Use when providing a default value for an absent Option
Details
Some → returns the inner valueNone → calls onNone() and returns its resultonNone is only called when needed (lazy)Example (Unwrapping with a fallback)
import { Option } from "effect"
console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))
// Output: 1
console.log(Option.none().pipe(Option.getOrElse(() => 0)))
// Output: 0
See
getOrNull to fall back to nullgetOrUndefined to fall back to undefinedgetOrThrow to throw on NoneSignature
declare const getOrElse: { <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => B | A; <A, B>(self: Option<A>, onNone: LazyArg<B>): A | B; }
Since v2.0.0