import { pipe } from "./composition.ts"; /** * Get a function to check that inputs are instances of a given type */ export function isinstance( ref: { new (...args: any[]): T }, ): (input: S) => input is Extract { return (x): x is Extract => x instanceof ref; } /** * Check that a value is not null, throwing an error if it is */ export function nn(value: T | null): T { if (value === null) { throw new Error("null value"); } else { return value; } } /** * Check that a value is not undefined, throwing an error if it is */ export function nu(value: T | undefined): T { if (typeof value === "undefined") { throw new Error("undefined value"); } else { return value; } } /** * Check that a value is not null nor undefined, throwing an error if it is */ export const nnu: (value: T | null | undefined) => T = pipe(nn, nu);