effect-io-ai

Package: effect
Module: Array

Array.fromNullishOr

Converts a nullable value to an array: null/undefined becomes [], anything else becomes [value].

When to use

Use to treat a nullable single value as zero or one array element.

Example (Converting nullable values to an array)

import { Array } from "effect"

console.log(Array.fromNullishOr(1)) // [1]
console.log(Array.fromNullishOr(null)) // []
console.log(Array.fromNullishOr(undefined)) // []

See

Signature

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

Source

Since v4.0.0