Skip to main content
Module

x/fun/mod.ts>optics.iso

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function optics.iso
import { optics } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { iso } = optics;

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 "./optics.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]