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.

14 lines (11 loc) 427 B
import { flow } from "fp-ts/lib/function"; import * as e from "fp-ts/lib/Either"; import { SmartConstructor, SmartType } from "../utilTypes"; import { mkInt } from "./int"; import { mkPositiveNum } from "./positiveNum"; export type PositiveInt = SmartType<number, "PositiveInt">; export const mkPositiveInt: SmartConstructor<PositiveInt> = flow( mkInt, e.chain(mkPositiveNum), e.map((x: number) => x as PositiveInt) );