Skip to main content
Module

x/fun/mod.ts>sortable.fromSort

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function sortable.fromSort
import { sortable } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { fromSort } = sortable;

Derives an Sortable from a Compare function.

Examples

Example 1

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

const date = fromSort<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