Skip to main content
Module

x/fun/refinement.ts>struct

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

Create a Refinement from a struct of refinements, where each index of a type much match the originated refinement type, key for key.

Examples

Example 1

import * as R from "./refinement.ts";

const struct = R.struct({
  num: R.number,
  str: R.string
});

const result1 = struct(null); // false
const result2 = struct({}); // false
const result3 = struct({ num: "Hello", str: 1 }); // false
const result4 = struct({ num: 1, str: "Hello" });
// true, variable has type { num: number, str: string }
const result5 = struct([1, "Hello", "Goodbye"]); // false

Parameters

items: [K in keyof A]: Refinement<unknown, A[K]>

Returns

Refinement<unknown, readonly [K in keyof A]: A[K]>