Package: effect
Module: Option
Returns the fallback Option if self is None; otherwise returns self.
When to use
Use when you need a lazy fallback Option, such as when building priority
chains of optional values.
Details
Some → returns self unchangedNone → evaluates and returns that()that is lazily evaluatedExample (Providing a fallback Option)
import { Option } from "effect"
console.log(Option.none().pipe(Option.orElse(() => Option.some("b"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'b' }
console.log(Option.some("a").pipe(Option.orElse(() => Option.some("b"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'a' }
See
orElseSome to wrap the fallback value in Some automaticallyfirstSomeOf to pick the first Some from a collectionSignature
declare const orElse: { <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<B | A>; <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>; }
Since v2.0.0