<A>(self: Array<A>): self is NonEmptyArray<A>Checks whether a mutable Array is non-empty, narrowing the type to
NonEmptyArray.
When to use
Use when you need the narrowed value to remain a mutable Array after proving
it has at least one element.
Example (Checking for a non-empty array)
import { Array } from "effect"
console.log(Array.isArrayNonEmpty([])) // false
console.log(Array.isArrayNonEmpty([1, 2, 3])) // trueexport const const isArrayNonEmpty: <A>(
self: Array<A>
) => self is NonEmptyArray<A>
Checks whether a mutable Array is non-empty, narrowing the type to
NonEmptyArray.
When to use
Use when you need the narrowed value to remain a mutable Array after proving
it has at least one element.
Example (Checking for a non-empty array)
import { Array } from "effect"
console.log(Array.isArrayNonEmpty([])) // false
console.log(Array.isArrayNonEmpty([1, 2, 3])) // true
isArrayNonEmpty: <function (type parameter) A in <A>(self: Array<A>): self is NonEmptyArray<A>A>(self: A[]self: interface Array<T>Array<function (type parameter) A in <A>(self: Array<A>): self is NonEmptyArray<A>A>) => self: A[]self is 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) A in <A>(self: Array<A>): self is NonEmptyArray<A>A> = import internalArrayinternalArray.const isArrayNonEmpty: <A>(
self: ReadonlyArray<A>
) => self is NonEmptyArray<A>
isArrayNonEmpty