import { eq } from "https://deno.land/x/fun@v2.0.0-alpha.6/mod.ts";
const { lazy } = eq;
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, Eq } from "./eq.ts";
import { pipe } from "./fn.ts";
type Person = { name: string, child?: Person };
// Annotating the type is required for recursion
const person: Eq<Person> = lazy('Person', () => pipe(
struct({ name: string }),
intersect(partial({ child: person }))
));
const icarus = { name: "Icarus" };
const daedalus = { name: "Daedalus", child: icarus };
const result1 = person.equals(icarus)(daedalus); // false
const result2 = person.equals(daedalus)(daedalus); // true