<Elements extends NonEmptyArray<unknown>>(
...elements: Elements
): NonEmptyArray<Elements[number]>Creates a NonEmptyArray from one or more elements.
When to use
Use when you need to create a typed non-empty array from literal values.
Details
The element type is inferred as the union of all arguments. Because at least
one argument is required, this always returns a NonEmptyArray.
Example (Creating an array from values)
import { Array } from "effect"
const result = Array.make(1, 2, 3)
console.log(result) // [1, 2, 3]export const const make: <
Elements extends NonEmptyArray<unknown>
>(
...elements: Elements
) => NonEmptyArray<Elements[number]>
Creates a NonEmptyArray from one or more elements.
When to use
Use when you need to create a typed non-empty array from literal values.
Details
The element type is inferred as the union of all arguments. Because at least
one argument is required, this always returns a NonEmptyArray.
Example (Creating an array from values)
import { Array } from "effect"
const result = Array.make(1, 2, 3)
console.log(result) // [1, 2, 3]
make = <function (type parameter) Elements in <Elements extends NonEmptyArray<unknown>>(...elements: Elements): NonEmptyArray<Elements[number]>Elements extends type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<unknown>>(
...elements: Elements extends NonEmptyArray<unknown>elements: function (type parameter) Elements in <Elements extends NonEmptyArray<unknown>>(...elements: Elements): NonEmptyArray<Elements[number]>Elements
): type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<function (type parameter) Elements in <Elements extends NonEmptyArray<unknown>>(...elements: Elements): NonEmptyArray<Elements[number]>Elements[number]> => elements: Elements extends NonEmptyArray<unknown>elements