Skip to main content
Module

x/fun/mod.ts>refinement.partial

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

Create a Refinement from a struct of refinements, where each index of a type much match the originated refinement type, key for key, or not have that property at all. This is distinct from the property being null or undefined.

Examples

Example 1

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

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

const result1 = struct(null); // false
const result2 = struct({}); // true,
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({
  num: 1,
  str: "Hello",
  other: "Goodbye"
}); // true, variable ahs type { num?: number, str?: string }

Parameters

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

Returns

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