Skip to main content
Module

x/fun/refinement.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.12/refinement.ts";

The Refinement type represents a function that takes a type and returns a boolean. It denotes a function that narrows a type at runtime. For example the function (n: unknown): n is number => typeof n === "number" is the refinement type Refinement<unknown, number>. The primary use for Refinement is to align the runtime value with compile time types.

Variables

The canonical implementation of Schemable for UnknownRefinement. It contains the methods unknown, string, number, boolean, literal, nullable, undefinable, record, array, tuple, struct, partial, intersect, union, and lazy.

Functions

Compose two refinements into a new refinement that returns true if both of the two input refinements return true.

Turn a Refinement<unknown, A> into Refinement<unknown, ReadonlyArray<A>>.

An instance of Refinement<unknown, boolean>.

Compose two refinements, A -> B and B -> C creating a Refinement<A, C>.

Construct a refinement from a function (a: A) => Either<J, I> where Left denotes that a type does not satisfy the refinement.

Construct a refinement from a function (a: A) => Option where None denotes that a type does not satisfy the refinement.

Create a identity refinement that always returns true as at the type level a type A is always a type A.

Intersect is an alias of and.

An instance of Refinement<unknown, Array<unknown>>.

Creates an instance Refinement<unknown, Array<unknown> & { length: N }> where N is a number.

An instance of Refinement<unknown, Record<string, unknown>>.

Lazy is used to handle the case where a refinement is recursive.

Creates an instance of Refinement<unknown, P> where P is a union of literal values.

Turn a Refinement<A, B> into Refinement<null | A, null | B>.

An instance of Refinement<unknown, number>.

Compose two refinements into a new refinement that returns true if either of the two input refinements return true.

Create a Refinement from a struct of refinements, where each index of a type much match the originated refinement type, key for key, or not have that property at all. This is distinct from the property being null or undefined.

Turn a Refinement<unknown, A> into Refinement<unknown, ReadonlyRecord<A>>.

An instance of Refinement<unknown, string>.

Create a Refinement from a struct of refinements, where each index of a type much match the originated refinement type, key for key.

Create a Refinement from an array of refinements, where each index of a type much match the originated refinement type.

Turn a Refinement<A, B> into Refinement<undefined | A, undefined | B>.

Union is an alias of or.

An instance of Refinement<unknown, unknown>.

Interfaces

Specifies Refinement as a Higher Kinded Type, with covariant parameter B corresponding to the 0th index of any substitutions and contravariant parameter A corresponding to the 0th index of any substitutions.

Specifies Refinement<unknown, B> as a Higher Kinded Type, with covariant parameter B corresponding to the 0th index of any substitutions.

Type Aliases

A type that matches any refinement type.

The refinement type is a function that returns a boolean indicating that a value satisfies a type.

The ToIn type takes a Refinement type and returns the type of its input.

The ToOut type takes a Refinement type and returns the type of its output refinement.