Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>optic.iso

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function optic.iso
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

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)

Parameters

view: (s: S) => A
review: (a: A) => S
optional
modify: (modifyFn: (a: A) => A) => (s: S) => S = [UNSUPPORTED]