Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/fun/newtype.ts

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

Newtype presents a type level "rebranding" of an existing type.

It's basic purpose is to create a branded type from an existing type. This is much like using TypeScript type aliases, ie. type MyNumber = number. However, Newtype will prevent the existing type from being used where the Branded type is specified.

Functions

Retype an existing Combinable from an inner type to a Newtype.

Retype an existing Comparable from an inner type to a Newtype.

Retype an existing Initializable from an inner type to a Newtype.

Retype an existing Sortable from an inner type to a 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.

If the Newtype and its underlying value are not referentially transparent (meaning they can always be swapped) then you can create an instance of Prism for the Newtype in order to optionally map into the Newtype given some Predicate.

Type Aliases

A type alias for Newtype<any, any> that is useful when constructing Newtype related runtime instances.

Create a branded type from an existing type. The branded type can be used anywhere the existing type can, but the existing type cannot be used where the branded one can.

Extracts the inner type value from a Newtype.