Skip to main content
Module

x/fun/refinement.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/refinement.ts";

Lazy is used to handle the case where a refinement is recursive.

Examples

Example 1

import type { Refinement } from "./refinement.ts";
import * as R from "./refinement.ts";

type Person = { name: string; age: number; children: ReadonlyArray<Person> };

const person: Refinement<unknown, Person> = R.lazy("Person", () =>
  R.struct({
    name: R.string,
    age: R.number,
    children: R.array(person),
  }));

const rufus = { name: "Rufus", age: 1, children: [] };
const brandon = { name: "Brandon", age: 37, children: [rufus] };

const result1 = person(null); // false
const result2 = person(rufus); // true, rufus: Person
const result3 = person(brandon); // true, brandon: Person

Type Parameters

A
B extends A

Parameters

_: string
refinement: () => Refinement<A, B>