UNPKG

1.58 kBTypeScriptView Raw
1import { IterationOf } from '../Iteration/IterationOf';
2import { Iteration } from '../Iteration/Iteration';
3import { Pos } from '../Iteration/Pos';
4import { Prepend } from './Prepend';
5import { Way } from '../Iteration/_Internal';
6import { List } from './List';
7import { Prev } from '../Iteration/Prev';
8import { Cast } from '../Any/Cast';
9import { Tail } from './Tail';
10import { Extends } from '../Any/Extends';
11/**
12 * starts in reverse from `N` till `N` = 0
13 * @hidden
14 */
15declare type TakeForth<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
16 0: TakeForth<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
17 1: LN;
18}[Extends<-1, Pos<I>>];
19/**
20 * starts in reverse from the end till `N` = 0
21 * @hidden
22 */
23declare type TakeBack<L extends List, N extends Iteration> = {
24 0: TakeBack<Tail<L>, Prev<N>>;
25 1: L;
26}[Extends<0, Pos<N>>];
27/**
28 * @hidden
29 */
30declare type __Take<L extends List, N extends Iteration, way extends Way> = {
31 '->': TakeForth<L, N>;
32 '<-': TakeBack<L, N>;
33}[way];
34/**
35 * @hidden
36 */
37export declare type _Take<L extends List, N extends number, way extends Way = '->'> = __Take<L, IterationOf<N>, way> extends infer X ? Cast<X, List> : never;
38/**
39 * Extract `N` entries out of `L`
40 * @param L to extract from
41 * @param N to extract out
42 * @param way (?=`'->'`) to extract from end
43 * @returns [[List]]
44 * @example
45 * ```ts
46 * ```
47 */
48export declare type Take<L extends List, N extends number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Take<L, N, way> : never : never;
49export {};