UNPKG

rivo

Version:

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

29 lines (25 loc) • 960 B
import type { List } from "."; import type { Args, GenericFn, GenericResolver } from "../HKT"; import type { Broaden } from "../helpers"; /** * Append an element to a {@link List} (i.e., fixed-length tuple). * * Sig: `<T>(x: T, xs: List<T>) => List<T>` */ export type Append<T, TS extends List> = TS extends unknown[] ? [...TS, T] : readonly [...TS, T]; interface Resolver extends GenericResolver<[unknown, List], List> { on1_: ([x]: Args<this>) => [[List<Broaden<typeof x>>], List<Broaden<typeof x>>]; on_1: ([, xs]: Args<this>) => [ [Broaden<(typeof xs)[number]>], List<Broaden<(typeof xs)[number]>>, ]; on11: ([x, xs]: Args<this>) => [[], List<typeof x | (typeof xs)[number]>]; } /** * [Fn] Append an element to a {@link List} (i.e., fixed-length tuple). * * Sig: `<T>(x: T, xs: List<T>) => List<T>` */ export default interface AppendFn extends GenericFn<Resolver> { def: ([x, xs]: Args<this>) => Append<typeof x, typeof xs>; }