Skip to main content
Module

x/fun/optics.ts>index

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

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

Examples

Example 1

import * as O from "./optics.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>