Package: effect
Module: Option
Returns Some of the fallback value if self is None; otherwise returns
self.
When to use
Use when providing a default plain value (not an Option) as fallback
Details
Some → returns self unchangedNone → calls onNone(), wraps result in Some, and returns itExample (Providing a fallback value)
import { Option } from "effect"
console.log(Option.none().pipe(Option.orElseSome(() => "b")))
// Output: { _id: 'Option', _tag: 'Some', value: 'b' }
console.log(Option.some("a").pipe(Option.orElseSome(() => "b")))
// Output: { _id: 'Option', _tag: 'Some', value: 'a' }
See
orElse when the fallback is itself an OptionSignature
declare const orElseSome: { <B>(onNone: LazyArg<B>): <A>(self: Option<A>) => Option<B | A>; <A, B>(self: Option<A>, onNone: LazyArg<B>): Option<A | B>; }
Since v2.0.0