Skip to main content
Module

x/fun/sortable.ts>struct

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

Derives an Sortable from a structs of Sortables. The derived Sortable 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.

Examples

Example 1

import { struct, lt } from "./sortable.ts"
import { SortableNumber } from "./number.ts";
import { SortableString } from "./string.ts";
import { pipe } from "./fn.ts";

const ord = struct({ num: SortableNumber, str: SortableString });
const _lt = lt(ord);

const result1 = pipe(
  { num: 1, str: "a" },
  _lt({ str: "b", num: 2 })
); // true
const result2 = pipe(
  { num: 1, str: "a" },
  _lt({ str: "b", num: 1 })
); // true
const result3 = pipe(
  { num: 1, str: "a" },
  _lt({ str: "a", num: 1 })
); // false

Parameters

sorts: readonly [K in keyof A]: Sortable<A[K]>

Returns

Sortable<readonly [K in keyof A]: A[K]>