Skip to main content
Module

x/fun/ord.ts>fromCompare

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function fromCompare
import { fromCompare } from "https://deno.land/x/fun@v.2.0.0-alpha.11/ord.ts";

Derives an Ord from a Compare function.

Examples

Example 1

import { clamp, lte, min, fromCompare, sign } from "./ord.ts";
import { pipe } from "./fn.ts";

const date = fromCompare<Date>(
  (fst, snd) => sign(fst.valueOf() - snd.valueOf())
);

const now = new Date();
const later = new Date(Date.now() + 60 * 60 * 1000);
const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);

const result1 = pipe(now, lte(date)(later)); // true
const result2 = pipe(tomorrow, clamp(date)(now, later)); // later
const result3 = pipe(tomorrow, min(date)(now)); // now