UNPKG

1.82 kBTypeScriptView Raw
1import { Concat } from './Concat';
2import { Append } from './Append';
3import { Cast } from '../Any/Cast';
4import { Length } from './Length';
5import { Iteration } from '../Iteration/Iteration';
6import { IterationOf } from '../Iteration/IterationOf';
7import { Next } from '../Iteration/Next';
8import { Pos } from '../Iteration/Pos';
9import { List } from './List';
10import { UnionOf } from './UnionOf';
11import { Naked } from './_Internal';
12import { Extends } from '../Any/Extends';
13import { Boolean } from '../Boolean/_Internal';
14import { Not } from '../Boolean/Not';
15import { And } from '../Boolean/And';
16/**
17 * @hidden
18 */
19declare type UnNestLoose<L extends List> = (UnionOf<L> extends infer UL ? UL extends unknown ? UL extends List ? UnionOf<UL> : UL : never : never)[] & {};
20/**
21 * @hidden
22 */
23declare type Flatter<L extends List, LN extends List, I extends Iteration> = L[Pos<I>] extends infer LP ? LP extends List ? Concat<LN, L[Pos<I>]> : Append<LN, L[Pos<I>]> : never;
24/**
25 * @hidden
26 */
27declare type UnNestStrict<L extends List, LN extends List = [], I extends Iteration = IterationOf<0>> = {
28 0: UnNestStrict<L, Flatter<L, LN, I>, Next<I>>;
29 1: LN;
30}[Extends<Pos<I>, Length<L>>];
31/**
32 * @hidden
33 */
34declare type __UnNest<L extends List, strict extends Boolean> = {
35 0: UnNestLoose<L>;
36 1: UnNestStrict<L>;
37}[And<Not<Extends<number, Length<L>>>, strict>];
38/**
39 * @hidden
40 */
41export declare type _UnNest<L extends List, strict extends Boolean> = __UnNest<Naked<L>, strict> extends infer X ? Cast<X, List> : never;
42/**
43 * Remove a dimension of `L`
44 * @param L to un-nest
45 * @param strict (?=`1`) `0` to not preserve tuples
46 * @returns [[List]]
47 * @example
48 * ```ts
49 * ```
50 */
51export declare type UnNest<L extends List, strict extends Boolean = 1> = L extends unknown ? _UnNest<L, strict> : never;
52export {};