import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { lens } = optic;
Construct a Lens<S, A> from view and modify functions.
Examples
Example 1
Example 1
import type { NonEmptyArray } from "./array.ts";
import * as O from "./optic.ts";
import * as A from "./array.ts";
import { pipe } from "./fn.ts";
const head = <A>() => O.lens<NonEmptyArray<A>, A>(
([head]) => head,
mod => ([head, ...rest]) => [mod(head), ...rest],
);
const headNum = head<number>();
const result1 = headNum.view(A.array(1, 2, 3)); // 1
const result2 = headNum.modify((n: number) => n + 100)(A.array(1, 2, 3));
// [100, 2, 3]