[d24f17c] | 1 | import { Pos } from '../Iteration/Pos';
|
---|
| 2 | import { Concat } from '../List/Concat';
|
---|
| 3 | import { Length } from '../List/Length';
|
---|
| 4 | import { Next } from '../Iteration/Next';
|
---|
| 5 | import { Cast } from '../Any/Cast';
|
---|
| 6 | import { Parameters } from './Parameters';
|
---|
| 7 | import { Return } from './Return';
|
---|
| 8 | import { IterationOf } from '../Iteration/IterationOf';
|
---|
| 9 | import { Iteration } from '../Iteration/Iteration';
|
---|
| 10 | import { NonNullableFlat } from '../Object/NonNullable';
|
---|
| 11 | import { x } from '../Any/x';
|
---|
| 12 | import { List } from '../List/List';
|
---|
| 13 | import { Function } from './Function';
|
---|
| 14 | import { Extends } from '../Any/Extends';
|
---|
| 15 | import { Tail } from '../List/Tail';
|
---|
| 16 | import { RequiredKeys } from '../List/RequiredKeys';
|
---|
| 17 | /**
|
---|
| 18 | * @hidden
|
---|
| 19 | */
|
---|
| 20 | declare type _SplitParams<P extends List, PSplit extends List[] = [], PRest extends List = Tail<P>> = {
|
---|
| 21 | 0: P extends [...infer A, ...PRest] ? _SplitParams<Tail<P>, [...PSplit, A], Tail<PRest>> : never;
|
---|
| 22 | 1: PSplit;
|
---|
| 23 | 2: P[number][][];
|
---|
| 24 | }[number extends Length<P> ? 2 : P extends [] ? 1 : 0];
|
---|
| 25 | /**
|
---|
| 26 | * Splits tuples to preserve their labels
|
---|
| 27 | * @hidden
|
---|
| 28 | */
|
---|
| 29 | declare type SplitParams<P extends List> = _SplitParams<P> extends infer X ? Cast<X, List[]> : never;
|
---|
| 30 | /**
|
---|
| 31 | * @hidden
|
---|
| 32 | */
|
---|
| 33 | declare type _JoinParams<PSplit extends List[], L extends List = []> = {
|
---|
| 34 | 0: _JoinParams<Tail<PSplit>, [...L, ...PSplit[0]]>;
|
---|
| 35 | 1: L;
|
---|
| 36 | 2: PSplit[number][];
|
---|
| 37 | }[number extends Length<PSplit> ? 2 : PSplit extends [] ? 1 : 0];
|
---|
| 38 | /**
|
---|
| 39 | * Undoes the job of [[SplitParams]]
|
---|
| 40 | * @hidden
|
---|
| 41 | */
|
---|
| 42 | declare type JoinParams<P extends List[]> = _JoinParams<P> extends infer X ? Cast<X, List> : never;
|
---|
| 43 | /**
|
---|
| 44 | * @hidden
|
---|
| 45 | */
|
---|
| 46 | declare type GapOf<L1 extends List, L2 extends List[], LN extends List, I extends Iteration> = L1[Pos<I>] extends x ? Concat<LN, L2[Pos<I>]> : LN;
|
---|
| 47 | /**
|
---|
| 48 | * @hidden
|
---|
| 49 | */
|
---|
| 50 | declare type _GapsOf<L1 extends List, L2 extends List[], LN extends List = [], L2D extends List[] = L2, I extends Iteration = IterationOf<0>> = {
|
---|
| 51 | 0: _GapsOf<L1, L2, GapOf<L1, L2, LN, I>, Tail<L2D>, Next<I>>;
|
---|
| 52 | 1: Concat<LN, JoinParams<L2D>>;
|
---|
| 53 | }[Extends<Pos<I>, Length<L1>>];
|
---|
| 54 | /**
|
---|
| 55 | * @hidden
|
---|
| 56 | */
|
---|
| 57 | declare type GapsOf<L1 extends List, L2 extends List> = _GapsOf<L1, SplitParams<L2>> extends infer X ? Cast<X, List> : never;
|
---|
| 58 | /**
|
---|
| 59 | * @hidden
|
---|
| 60 | */
|
---|
| 61 | declare type Gaps<L extends List> = Cast<NonNullableFlat<{
|
---|
| 62 | [K in keyof L]?: L[K] | x;
|
---|
| 63 | }>, List>;
|
---|
| 64 | /**
|
---|
| 65 | * Curry a [[Function]]
|
---|
| 66 | * @param F to curry
|
---|
| 67 | * @returns [[Function]]
|
---|
| 68 | * @example
|
---|
| 69 | * ```ts
|
---|
| 70 | * import {F} from 'ts-toolbelt'
|
---|
| 71 | *
|
---|
| 72 | * /// If you are looking for creating types for `curry`
|
---|
| 73 | * /// It handles placeholders and variable arguments
|
---|
| 74 | * declare function curry<Fn extends F.Function>(fn: Fn): F.Curry<Fn>
|
---|
| 75 | * ```
|
---|
| 76 | */
|
---|
| 77 | export declare type Curry<F extends Function> = <P extends Gaps<Parameters<F>>, G extends List = GapsOf<P, Parameters<F>>, R extends any = Return<F>>(...p: Gaps<Parameters<F>> | P) => RequiredKeys<G> extends never ? R : Curry<(...p: G) => R>;
|
---|
| 78 | export {};
|
---|