import type { TypedArray } from "./typedarray.js"; /** * Returns an array's value type. Assumes array is homogeneous (only type of * first element will be considered). */ export type ArrayValue = T[0]; /** * Somewhat similar, but recursive version of {@link ArrayValue}. If `T` is an * array/typedarray recursively descends into it or (if not an array) returns * `T`. Assumes arrays at each level are homogeneous (only type of first * elements will be considered). */ export type DeepArrayValue = T extends unknown[] ? DeepArrayValue : T extends TypedArray ? number : T; /** * Defines a fixed sized, iterable tuple with elements of type `T` and * length `N`. */ export type Tuple = [T, ...T[]] & { length: N; } & Iterable; /** * Extracts a tuple's length / size. */ export type TupleLength = T["length"]; /** * Returns 1 if T is empty tuple, else 0 */ export type IsEmpty = T extends [] ? 1 : 0; /** * Extracts the first element of a tuple. */ export type Head = T extends [infer A, ...unknown[]] ? A : never; /** * Extracts everything except the first element from a tuple. */ export type Tail = T extends [unknown, ...infer A] ? A : never; /** * Adds an element at the start of an tuple. */ export type Prepend = [T, ...U]; /** * Internal version of {@link Reverse} accepting 1 extra argument for * the accumulated value. */ type ReverseReducer = { 0: C; 1: Prepend, C>; 2: ReverseReducer, Prepend, C>>; }[Tail extends [] ? (Head extends never ? 0 : 1) : 2]; /** * Reverses the order of elements from a tuple. */ export type Reverse = ReverseReducer; /** * Extracts the last element from a tuple. */ export type Last = { 0: Last>; 1: Head; }[IsEmpty>]; /** * Extracts everything except the last element from a tuple. */ export type ButLast = { 0: ButLast, Prepend, C>>; 1: Reverse; }[IsEmpty>]; export {}; //# sourceMappingURL=tuple.d.ts.map