Skip to main content
Module

x/fun/comparable.ts>lazy

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function lazy
import { lazy } from "https://deno.land/x/fun@v2.0.0/comparable.ts";

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>