import { affineFold } from "https://deno.land/x/fun@v2.0.0/optic.ts";
Construct an AffineFold<S, A> from view and modify functions.
Examples
Example 1
Example 1
import type { Either } from "./either.ts";
import * as O from "./optic.ts";
import * as E from "./either.ts";
const right = <R, L = unknown>() => O.affineFold<Either<L, R>, R>(
E.getRight,
E.map,
);
const numberRight = right<number, string>();
const result1 = numberRight.view(E.right(1)); // Some(1)
const result2 = numberRight.view(E.left("Hello")); // None
const result3 = numberRight.modify(n => n + 1)(E.right(1)); // Right(2)
const result4 = numberRight.modify(n => n + 1)(E.left("Hello"));
// Left("Hello")