import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { iso } = optic;
Construct an Iso<S, A> from view and review functions, with an optional modify function if it is different from
Examples
Example 1
Example 1
import * as O from "./optic.ts";
import { Option, match, some, none, map, fromPredicate } from "./option.ts";
import { pipe, identity } from "./fn.ts";
const { view, review, modify }: O.Iso<Option<number>, number> = O.iso(
match(() => 0, identity),
fromPredicate(n => n !== 0),
map,
);
const result1 = view(some(1)); // 1
const result2 = view(none); // 0
const result3 = review(1); // Some(1)
const result4 = review(0); // None
const result5 = modify(n => n + 100)(some(1)); // Some(101)
const result6 = modify(n => n + 100)(none); // Some(100)