UNPKG

rivo

Version:

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

25 lines (22 loc) • 831 B
import type { Args, Fn } from "../HKT"; import type { List } from "../List"; import type { Nat } from "../Num"; import type { Compare } from "../Num/Compare"; import type { Inc } from "../Num/Int/Inc"; import type { EQ, GT } from "../typeclass/Ord"; /** * Generate a {@link List} of numbers from `From` to `To` (exclusive). * * Sig: `(from: Int, to: Int) => List<Int>` */ export type RangeOf<From extends Nat, To extends Nat> = Compare<From, To> extends GT | EQ ? readonly [] : readonly [From, ...RangeOf<From extends Nat ? Inc<From> : never, To>]; /** * [Fn] Generate a {@link List} of numbers from `From` to `To` (exclusive). * * Sig: `(from: Int, to: Int) => List<Int>` */ export default interface RangeOfFn extends Fn<[Nat, Nat], List<Nat>> { def: ([from, to]: Args<this>) => RangeOf<typeof from, typeof to>; }