UNPKG

rivo

Version:

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

27 lines (23 loc) • 867 B
import type { Args, GenericFn, GenericResolver } from "../HKT"; import type { Dec } from "../Num/Int/Dec"; import type { Nat } from "../Num/Nat"; /** * Repeat `T` for `N` times. * * Sig: `<N extends Nat, T>(n: N, x: T) => readonly [T, T, ...]` */ export type Repeat<N extends Nat, T> = N extends 0 ? readonly [] : readonly [T, ...Repeat<Dec<N>, T>]; interface Resolver extends GenericResolver<[Nat, unknown], readonly unknown[]> { on1_: ([n]: Args<this>) => [[unknown], Repeat<typeof n, unknown>]; on_1: ([, x]: Args<this>) => [[Nat], readonly (typeof x)[]]; on11: ([n, x]: Args<this>) => [[], Repeat<typeof n, typeof x>]; } /** * [Fn] Repeat `T` for `N` times. * * Sig: `<N extends Nat, T>(n: N, x: T) => readonly [T, T, ...]` */ export interface RepeatFn extends GenericFn<Resolver> { def: ([n, x]: Args<this>) => Repeat<typeof n, typeof x>; }