Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>comparable.lazy

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function comparable.lazy
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

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

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