effect-io-ai

Package: effect
Module: Option

Option.fromNullishOr

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

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

Signature

declare const fromNullishOr: <A>(a: A) => Option<NonNullable<A>>

Source

Since v4.0.0