Skip to main content
Module

x/fun/mod.ts>optic.first

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

A preconstructed composed lens that focuses on the First value of a Pair.

Examples

Example 1

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

// Pair<numerator, denominator>
type Rational = P.Pair<number, number>;

const numerator = pipe(O.id<Rational>(), O.first);

const result = pipe(numerator, O.view(P.pair(1, 1))); // 1

type

<U extends Tag, S, B, A>(optic: Optic<U, S, Pair<A, B>>) => Optic<Align<U, LensTag>, S, A>