import { comparable } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { lazy } = comparable;
Create a eq that evaluates lazily. This is useful for equality of recursive types (either mutual or otherwise).
Examples
Example 1
Example 1
import { lazy, intersect, struct, partial, string, Comparable } from "./comparable.ts";
import { pipe } from "./fn.ts";
type Person = { name: string, child?: Person };
// Annotating the type is required for recursion
const person: Comparable<Person> = lazy('Person', () => pipe(
struct({ name: string }),
intersect(partial({ child: person }))
));
const icarus = { name: "Icarus" };
const daedalus = { name: "Daedalus", child: icarus };
const result1 = person.compare(icarus)(daedalus); // false
const result2 = person.compare(daedalus)(daedalus); // true
Parameters
f: () => Comparable<A>