1 | import { IterationOf } from '../Iteration/IterationOf';
|
---|
2 | import { Iteration } from '../Iteration/Iteration';
|
---|
3 | import { Pos } from '../Iteration/Pos';
|
---|
4 | import { Prepend } from './Prepend';
|
---|
5 | import { Way } from '../Iteration/_Internal';
|
---|
6 | import { List } from './List';
|
---|
7 | import { Prev } from '../Iteration/Prev';
|
---|
8 | import { Cast } from '../Any/Cast';
|
---|
9 | import { Tail } from './Tail';
|
---|
10 | import { Extends } from '../Any/Extends';
|
---|
11 | /**
|
---|
12 | * starts in reverse from `N` till `N` = 0
|
---|
13 | * @hidden
|
---|
14 | */
|
---|
15 | declare 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 | */
|
---|
23 | declare 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 | */
|
---|
30 | declare 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 | */
|
---|
37 | export 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 | */
|
---|
48 | export declare type Take<L extends List, N extends number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Take<L, N, way> : never : never;
|
---|
49 | export {};
|
---|