import { Cast } from './cast'; /** * the first element */ export type Head = T extends [infer R, ...any] ? R : never; /** * all but the first element */ export type Tail = T extends [any, ...infer R] ? R : never; /** * all but the last element */; export type Body = T extends [...infer R, any] ? R : never; /** * the last element */ export type Last = T extends [...any, infer R] ? R : never; /** * the length of the list */ export type Length = Cast; /** * Moves Values from the front of the right away to the end of the left. * * ShiftLeft<[0,1,2],[3,4,5,6],2> => [[0,1,2,3,4],[5,6]]] */ type ShiftLeft = Length extends count ? [left, right] : right extends [] ? [left, right] : ShiftLeft<[...left, Head], Tail, count>; /** * SplitArray<[0,1,2,3,4,5,6,7,8], 3> => [[0,1,2],[3,4,5,6,7,8]] */ export type SplitArray = ShiftLeft<[], array, count>; /** * Slice<[0,1,2,3,4,5,6,7,8], 2, 3> => [2,3,4] */ export type Slice> = Take>; /** * Take<2, [0,1,2,3,4]> => [0,1] */ export type Take = Cast[0], T>; /** * Skip<2, [0,1,2,3,4]> => [2,3,4] */ export type Skip = Cast[1], T>; /** * PartialList<[0,1,2,3]> => [0,1,2,3] | [0,1,2] | [0,1] | [0] | [] */ export type PartialList = T | ( T extends [...infer R, any] ? PartialList : [] );