rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
78 lines (72 loc) • 1.75 kB
TypeScript
import type AddFn from "./Add";
import type CompareFn from "./Compare";
import type IsNatFn from "./IsNat";
import type SubFn from "./Sub";
import type { PartialApply } from "../../HKT";
/**
* Alias for `number` to represent natural numbers.
*/
export type Nat = number;
/***********
* Methods *
***********/
/**
* Methods for `Nat`.
*/
export namespace Nat {
/**
* [Fn] Compare two {@link Nat}s.
*
* Sig: `(n: Nat, m: Nat) => Ordering`
*/
export type Compare = CompareFn;
/**
* [Fn] Compare a {@link Nat} with another {@link Nat}.
*
* Sig: `[m: Nat](n: Nat) => Ordering`
*/
export type CompareWith<M extends Nat> = PartialApply<CompareFn, [M], "_1">;
/**
* [Fn] Compare a {@link Nat} with another {@link Nat}.
*
* Sig: `[n: Nat](m: Nat) => Ordering`
*/
export type CompareAgainst<N extends Nat> = PartialApply<CompareFn, [N]>;
/**
* [Fn] Add two {@link Nat}s.
*
* Sig: `(n: Nat, m: Nat) => Nat`
*/
export type Add2 = AddFn;
/**
* [Fn] Add two {@link Nat}s.
*
* Sig: `[m: Nat](n: Nat) => Nat`
*/
export type Add<M extends Nat> = PartialApply<AddFn, [M], "_1">;
/**
* [Fn] Subtract two {@link Nat}s.
*
* Sig: `(n: Nat, m: Nat) => Nat`
*
* **⚠️ Warning:** `n` must be greater than or equal to `m`.
*/
export type Sub2 = SubFn;
/**
* [Fn] Subtract two {@link Nat}s.
*
* Sig: `[m: Nat](n: Nat) => Nat`
*
* **⚠️ Warning:** `n` must be greater than or equal to `m`.
*/
export type Sub<M extends Nat> = PartialApply<SubFn, [M], "_1">;
}
/******************
* Static members *
******************/
/**
* [Fn] Check if a value is {@link Nat}.
*
* Sig: `(x: unknown) => boolean`
*/
export type Nat$$IsNat = IsNatFn;