at(index): Lens
tsat: <A>(index: number) => Lens<A, A[]>;
tsat: <A>(index: number) => Lens<A, A[]>;
This combinator takes an index and, when passed to derive, returns an optic focused on the element at the index in the focused array.
Just like JavaScript's Array.at, a negative index counts back from the end of the array.
tsimport {at } from "@optics/react/combinators";constnumbersOptic =createState ([78, 90, 4, 7, 10, 789, 42, 90]);constfifthElementOptic =numbersOptic .derive (at (4));fifthElementOptic .get (); // 10numbersOptic .derive (at (-2)).get (); // 42
tsimport {at } from "@optics/react/combinators";constnumbersOptic =createState ([78, 90, 4, 7, 10, 789, 42, 90]);constfifthElementOptic =numbersOptic .derive (at (4));fifthElementOptic .get (); // 10numbersOptic .derive (at (-2)).get (); // 42