effect-io-ai

Package: effect
Module: Array

Array.NonEmptyArray

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)

See

Signature

type [A, ...A[]] = [A, ...Array<A>]

Source

Since v2.0.0