Package: effect
Module: Array
Reads an element at the given index safely, returning Option.some or
Option.none if the index is out of bounds.
When to use
Use when you need to read an array element by index and handle an
out-of-bounds index as Option.none.
Details
The index is floored to an integer. This never throws.
Example (Accessing indexes safely)
import { Array } from "effect"
console.log(Array.get([1, 2, 3], 1)) // Some(2)
console.log(Array.get([1, 2, 3], 10)) // None
See
getUnsafe for indexed access that throws when the index is out of boundshead for reading the first element as an Optionlast for reading the last element as an OptionSignature
declare const get: { (index: number): <A>(self: ReadonlyArray<A>) => Option.Option<A>; <A>(self: ReadonlyArray<A>, index: number): Option.Option<A>; }
Since v2.0.0