Hyperlinkv0.8.0-beta.28

Array

Array.ensureconsteffect/Array.ts:336
<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"]
constructorsoffromIterable
Source effect/Array.ts:3361 lines
export const ensure = <A>(self: ReadonlyArray<A> | A): Array<A> => Array.isArray(self) ? self : [self as A]
Referenced by 2 symbols