<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([])) // Noneexport const const head: <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
head: <function (type parameter) A in <A>(self: ReadonlyArray<A>): Option.Option<A>A>(self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>): Option.Option<A>A>) => import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in <A>(self: ReadonlyArray<A>): Option.Option<A>A> = const get: {
(index: number): <A>(
self: ReadonlyArray<A>
) => Option.Option<A>
<A>(
self: ReadonlyArray<A>,
index: number
): Option.Option<A>
}
get(0)