UNPKG

rivo

Version:

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

36 lines (33 loc) • 1.09 kB
import type { Int } from "."; import type { Arg0, Arg1, Fn } from "../../HKT"; import type { 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"; /** * Add two {@link Int}s. * * Sig: `(n: Int, m: Int) => Int` */ export type Add<N extends Int, M extends Int> = Int extends N | M ? number : IsPos<N> extends true ? IsPos<M> extends true ? AddNat<N, M> : CompareNat<N, Abs<M>> extends LT ? _StrToNum<`-${SubNat<Abs<M>, N>}`> : SubNat<N, Abs<M>> : IsPos<M> extends true ? CompareNat<M, Abs<N>> extends LT ? _StrToNum<`-${SubNat<Abs<N>, M>}`> : SubNat<M, Abs<N>> : _StrToNum<`-${AddNat<Abs<N>, Abs<M>>}`>; /** * [Fn] Add two {@link Int}s. * * Sig: `(n: Int, m: Int) => Int` */ export default interface AddFn extends Fn<[Int, Int], Int> { def: () => Add<Arg0<this>, Arg1<this>>; }