<A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>Checks whether a ReadonlyArray is non-empty, narrowing the type to
NonEmptyReadonlyArray.
When to use
Use when you need to prove a readonly array has at least one element without requiring mutable array methods afterward.
Example (Checking for a non-empty readonly array)
import { Array } from "effect"
console.log(Array.isReadonlyArrayNonEmpty([])) // false
console.log(Array.isReadonlyArrayNonEmpty([1, 2, 3])) // trueexport const const isReadonlyArrayNonEmpty: <A>(
self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
Checks whether a ReadonlyArray is non-empty, narrowing the type to
NonEmptyReadonlyArray.
When to use
Use when you need to prove a readonly array has at least one element without
requiring mutable array methods afterward.
Example (Checking for a non-empty readonly array)
import { Array } from "effect"
console.log(Array.isReadonlyArrayNonEmpty([])) // false
console.log(Array.isReadonlyArrayNonEmpty([1, 2, 3])) // true
isReadonlyArrayNonEmpty: <function (type parameter) A in <A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>A>(self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>A>) => self: readonly A[]self is type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>): self is NonEmptyReadonlyArray<A>A> =
import internalArrayinternalArray.const isArrayNonEmpty: <A>(
self: ReadonlyArray<A>
) => self is NonEmptyArray<A>
isArrayNonEmpty