<A>(self: ReadonlyArray<A> | A): Array<A>Normalizes a value that is either a single element or an array into an array.
When to use
Use to normalize input that may be a single value or an array into a consistent array.
Details
If the input is already an array, this returns it by reference. If the input
is a single value, this wraps it in a one-element array. This is useful for
APIs that accept A | Array<A>.
Example (Normalizing input)
import { Array } from "effect"
console.log(Array.ensure("a")) // ["a"]
console.log(Array.ensure(["a", "b", "c"])) // ["a", "b", "c"]export const const ensure: <A>(
self: ReadonlyArray<A> | A
) => Array<A>
Normalizes a value that is either a single element or an array into an array.
When to use
Use to normalize input that may be a single value or an array into a consistent
array.
Details
If the input is already an array, this returns it by reference. If the input
is a single value, this wraps it in a one-element array. This is useful for
APIs that accept A | Array<A>.
Example (Normalizing input)
import { Array } from "effect"
console.log(Array.ensure("a")) // ["a"]
console.log(Array.ensure(["a", "b", "c"])) // ["a", "b", "c"]
ensure = <function (type parameter) A in <A>(self: ReadonlyArray<A> | A): Array<A>A>(self: A | readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A> | A): Array<A>A> | function (type parameter) A in <A>(self: ReadonlyArray<A> | A): Array<A>A): interface Array<T>Array<function (type parameter) A in <A>(self: ReadonlyArray<A> | A): Array<A>A> => const Array: ArrayConstructorExposes the global array constructor.
When to use
Use to access native JavaScript array constructor methods such as isArray
or from from the Effect module namespace.
Example (Accessing the Array constructor)
import { Array } from "effect"
const arr = new Array.Array(3)
console.log(arr) // [undefined, undefined, undefined]
Array.ArrayConstructor.isArray(arg: any): arg is any[]isArray(self: A | readonly A[]self) ? self: A & any[]self : [self: A | readonly A[]self as function (type parameter) A in <A>(self: ReadonlyArray<A> | A): Array<A>A]