effect-io-ai

Package: effect
Module: Array

Array.head

Returns the first element of an array safely wrapped in Option.some, or Option.none if the array is empty.

When to use

Use to safely get the first element of an array that may be empty.

Example (Getting the first element)

import { Array } from "effect"

console.log(Array.head([1, 2, 3])) // Some(1)
console.log(Array.head([])) // None

See

Signature

declare const head: <A>(self: ReadonlyArray<A>) => Option.Option<A>

Source

Since v2.0.0