import { refinement } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { lazy } = refinement;
Lazy is used to handle the case where a refinement is recursive.
Examples
Example 1
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
B extends A
Parameters
refinement: () => Refinement<A, B>