Skip to main content
Module

x/fun/mod.ts>eq.lazy

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 eq.lazy
import { eq } from "https://deno.land/x/fun@v.2.0.0-alpha.11/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

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

Parameters

_: string
f: () => Eq<A>