Skip to main content
Module

x/fun/mod.ts>newtype.iso

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

If the Newtype and its underlying value are referentially transparent (meaning they can always be swapped) then you can create an instance of Iso for the Newtype for mapping back and forth.

Examples

Example 1

import * as N from "./newtype.ts";

type Real = N.Newtype<"Real", number>;

const isoReal = N.iso<Real>();

const result1: Real = isoReal.view(1); // Turn number into Real
const result2: number = isoReal.review(result1); // Turn Real into number