Skip to main content
Module

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

Variables

The canonical implementation of Contravariant for Ord. It contains the method contramap.

Functions

Derives an instance of Ord by take an existing Ord over D and a function that turns an L into D and returns an Ord over L.

Derives an Ord from a Compare function.

Derive an Ord with the reverse ordering of an existing Ord.

Returns an Ordering from any number according to its relationship with 0.

Derives an Ord from a structs of Ords. The derived Ord will compare two structs starting with the first defined key and return the first ordering that is non-zero, otherwise the two structs are equal.

Create a trivial Ord, where all values of A are considered equal.

Derives an Ord from a tuple of Ords. The derived Ord will compare two tuples starting at index 0 and return the first ordering that is non-zero, otherwise the two tuples are equal.

Interfaces

An Ord is an algebra with a notion of equality and order. Specifically, Ord extends Eq and thus inherites an equals method. For order it contains a signed comparison function, taking two values and returning -1, 0, or 1 when first < second, first === second, and first > second respectively.

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

Type Aliases

The Compare function takes to values of the same type and returns an ordering, indicating whether first is less than, equal to, or greater than `second.

The ordering type is the expected output of any Compare function. The canonical example is the output of the Array.sort function. For any two values first and second, Ordering means the following: