Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

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

Comparable is a structure that has an idea of comparability. Comparability means that two of the same type of object can be compared such that the condition of comparison can be true or false. The canonical comparison is equality.

Variables

A Comparable that compares booleans using strict equality.

A Comparable that compares number using strict equality.

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

A Comparable that compares strings using strict equality.

A Comparable that can compare any unknown values (and thus can compare any values). Underneath it uses strict equality for the comparison.

Functions

Creates a Comparable that compares readonly array with items that have the type compared in the supplied eq.

Create a Comparable from a Compare function.

Create a eq from two other eqs. The resultant eq checks that any two values are equal according to both supplied eqs.

Create a eq that evaluates lazily. This is useful for equality of recursive types (either mutual or otherwise).

Creates a Comparable that compares a union of literals using strict equality.

Create a eq from a method on a class or prototypical object. This exists because many objects in javascript do now allow you to pass an object method around on its own without its parent object. For example, if you pass Date.valueOf (type () => number) into another function and call it, the call will fail because valueOf does not carry the reference of its parent object around.

Creates a derivative Comparable that can also compare null values in addition to the source eq.

Create a eq that compares, key for key, structs according to the structure of the eqs passed into struct. It allows the values in the struct to be optional or null.

Create a Comparable using a Comparable and a function that takes a type L and returns a type D.

Create a Comparable that casts the inner type of another Comparable to Readonly.

Creates a Comparable that compares readonly records with items that have the type compared in the supplied eq.

Create a eq that compares, key for key, structs according to the structure of the eqs passed into struct.

Create a eq that tests the output of a thunk (IO). This assumes that the output of the thunk is always the same, which for true IO is not the case. This assumes that the context for the function is undefined, which means that it doesn't rely on "this" to execute.

Creates a eq that compares, index for index, tuples according to the order and eqs passed into tuple.

Creates a derivative Comparable that can also compare undefined values in addition to the source eq.

Create a Comparable from two other Comparables. The resultant Comparable checks that any two values are equal according to at least one of the supplied eqs.

Interfaces

A Comparable is an algebra with a notion of equality. Specifically, a Comparable for a type T has an equal method that determines if the two objects are the same. Comparables can be combined, like many algebraic structures. The combinators for Comparable in fun can be found in comparable.ts.

Specifies Comparable as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any Substitutions.

Specifies Comparable as a Higher Kinded Type, with contravariant parameter D corresponding to the 0th index of any Substitutions.

Type Aliases

The compare function in a Comparable.