<A>(a: A): Array<NonNullable<A>>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)) // []Source effect/Array.ts:40181 lines
export const const fromNullishOr: <A>(
a: A
) => Array<NonNullable<A>>
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)) // []
fromNullishOr = <function (type parameter) A in <A>(a: A): Array<NonNullable<A>>A>(a: Aa: function (type parameter) A in <A>(a: A): Array<NonNullable<A>>A): interface Array<T>Array<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) A in <A>(a: A): Array<NonNullable<A>>A>> => a: Aa == null ? const empty: <NonNullable<A>>() => NonNullable<A>[]Creates an empty array.
When to use
Use to create a typed empty array without allocating placeholder elements.
Example (Creating an empty array)
import { Array } from "effect"
const result = Array.empty<number>()
console.log(result) // []
empty() : [a: NonNullable<A>a as type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) A in <A>(a: A): Array<NonNullable<A>>A>]Referenced by 2 symbols