UNPKG

smart-types-ts

Version:

A collection of _Smart Types_ and _Smart Constructors_ which enable you to be more strict when defining your application's important types/interfaces.

13 lines (10 loc) 420 B
import { flow } from "fp-ts/lib/function"; import * as e from "fp-ts/lib/Either"; import { SmartConstructor, SmartType } from "../utilTypes"; import { number } from "./number"; export type NegativeNum = SmartType<number, "NegativeNum">; export const mkNegativeNum: SmartConstructor<NegativeNum> = flow( number, e.chain(e.fromPredicate(x => x < 0, () => "Not a negative number")), e.map(x => x as NegativeNum) );