Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>optic.index

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function optic.index
import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { index } = optic;

A composible combinator that focuses on a value in an array at the given index.

Examples

Example 1

import * as O from "./optic.ts";
import { pipe } from "./fn.ts";

const second = pipe(
  O.id<ReadonlyArray<string>>(),
  O.index(1),
);

const result1 = pipe(second, O.view([])); // None
const result2 = pipe(second, O.view(["Hello", "World"])); // Some("World")

Parameters

index: number

Returns

<U extends Tag, S, A>(first: Optic<U, S, ReadonlyArray<A>>) => Optic<Align<U, AffineTag>, S, A>