Hyperlinkv0.8.0-beta.28

Array

Array.headconsteffect/Array.ts:1085
<A>(self: ReadonlyArray<A>): Option.Option<A>

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
Source effect/Array.ts:10851 lines
export const head: <A>(self: ReadonlyArray<A>) => Option.Option<A> = get(0)