Skip to main content
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.
Go to Latest
import * as fun from "https://deno.land/x/fun@v2.0.0-alpha.6/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 Eq from an inner type to a Newtype.

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

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

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

Type Aliases

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

Extracts the inner type value from a Newtype.

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.