Skip to content

index

index<A>(i): Optional<A[], A>

Defined in: Core/Optional.ts:82

Creates an Optional that focuses on an element at a given index in an array. Returns None when the index is out of bounds; set is a no-op when out of bounds.

A

number

Optional<A[], A>

const firstItem = Optional.index<string>(0);

pipe(["a", "b"], Optional.get(firstItem)); // Some("a")
pipe([], Optional.get(firstItem));         // None