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
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