import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { fold } = optic;
Construct a Fold<S, A> from view and modify functions.
Examples
Example 1
Example 1
import * as O from "./optic.ts";
import * as R from "./record.ts";
const values = <A>() => O.fold<Record<string, A>, A>(
Object.values,
R.map,
);
const numberValues = values<number>();
const result1 = numberValues.view({}); // []
const result2 = numberValues.view({ foo: 1 }); // [1]
const result3 = numberValues.modify(n => n + 1)({}); // {}
const result4 = numberValues.modify(n => n + 1)({ foo: 1 }); // { foo: 2 }