effect-io-ai

Package: effect
Module: Option

Option.fromNullOr

Converts a possibly null value into an Option, leaving undefined as a valid Some.

When to use

Use when you want to treat only null as absent while preserving undefined as a meaningful value.

Details

Example (Converting possibly null values to an Option)

import { Option } from "effect"

console.log(Option.fromNullOr(null))
// Output: { _id: 'Option', _tag: 'None' }

console.log(Option.fromNullOr(undefined))
// Output: { _id: 'Option', _tag: 'Some', value: undefined }

console.log(Option.fromNullOr(42))
// Output: { _id: 'Option', _tag: 'Some', value: 42 }

See

Signature

declare const fromNullOr: <A>(a: A) => Option<Exclude<A, null>>

Source

Since v4.0.0