UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

35 lines (32 loc) • 1.08 kB
import type { Int } from "."; import type { Arg0, Arg1, Fn } from "../../HKT"; import type { GT, LT } from "../../typeclass/Ord"; import type { Abs } from "../Abs"; import type { IsPos } from "../IsPos"; import type { Add as AddNat } from "../Nat/Add"; import type { Compare as CompareNat } from "../Nat/Compare"; import type { Sub as SubNat } from "../Nat/Sub"; import type { _StrToNum } from "../internal/_StrToNum"; /** * Subtract two {@link Int}s. * * Sig: `(n: Int, m: Int) => Int` */ export type Sub<N extends Int, M extends Int> = IsPos<N> extends true ? IsPos<M> extends true ? CompareNat<N, M> extends LT ? _StrToNum<`-${SubNat<M, N>}`> : SubNat<N, M> : AddNat<N, Abs<M>> : IsPos<M> extends true ? _StrToNum<`-${AddNat<Abs<N>, M>}`> : CompareNat<Abs<N>, Abs<M>> extends GT ? _StrToNum<`-${SubNat<Abs<N>, Abs<M>>}`> : SubNat<Abs<M>, Abs<N>>; /** * [Fn] Subtract two {@link Int}s. * * Sig: `(n: Int, m: Int) => Int` */ export default interface SubFn extends Fn<[Int, Int], Int> { def: () => Sub<Arg0<this>, Arg1<this>>; }