Skip to main content
Module

x/fun/ord.ts>struct

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 struct
import { struct } from "https://deno.land/x/fun@v2.0.0-alpha.10/ord.ts";

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.

Examples

Example 1

import { struct, lt } from "./ord.ts"
import { OrdNumber } from "./number.ts";
import { OrdString } from "./string.ts";
import { pipe } from "./fn.ts";

const ord = struct({ num: OrdNumber, str: OrdString });
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

ords: readonly [K in keyof A]: Ord<A[K]>

Returns

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