Package: effect
Module: Option
Converts a nullable value (null or undefined) into an Option.
When to use
Use when you need JavaScript nullish values to become absence at an API boundary while all other values, including falsy ones, remain present.
Details
null or undefined → NoneSome (typed as NonNullable<A>)Example (Converting nullable values to an Option)
import { Option } from "effect"
console.log(Option.fromNullishOr(undefined))
// Output: { _id: 'Option', _tag: 'None' }
console.log(Option.fromNullishOr(null))
// Output: { _id: 'Option', _tag: 'None' }
console.log(Option.fromNullishOr(1))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
See
fromNullOr to only treat null as absentfromUndefinedOr to only treat undefined as absentliftNullishOr to lift a nullable-returning functionSignature
declare const fromNullishOr: <A>(a: A) => Option<NonNullable<A>>
Since v4.0.0