diff --git a/src/FunctionX.ts b/src/FunctionX.ts index 9e4fb20..de4d9cd 100644 --- a/src/FunctionX.ts +++ b/src/FunctionX.ts @@ -24,6 +24,45 @@ type TTail = : T extends [] ? [] : never; +type TLast = T extends [] ? never : + T extends [infer T1] ? T1 : {0:TTail, 1:never}[T extends [infer T1, infer S] ? 0 : 1]; + +// type TInit = T extends [] +// ? [] +// : T extends [any] +// ? [] +// : (((...args: T) => void) extends ((first: infer T1, ...rest: infer T2) => void) ? +// (((a:T1,...rest:TInit)=>void) extends ((...all: infer AP)=>void) ? AP : never) : never) + +type Head = Tuple extends [infer H, ...any[]] ? H : never; +type Tail = ((...t: Tuple) => void) extends ((h: any, ...rest: infer R) => void) ? R : never; +type Unshift = ((h: Element, ...t: Tuple) => void) extends (...t: infer R) => void ? R : never; + +// https://github.com/Microsoft/TypeScript/pull/24897#issuecomment-401401470 +// he has a simpler head & tail than me! +type Reverse = Reverse_; +type Reverse_ = { + 1: Result, + 0: Reverse_, Unshift>> +}[Tuple extends [] ? 1 : 0]; + +// type TInit = { +// 0: ((...args: T) => void) extends ((first: infer T1, ...rest: infer T2) => void) +// ? (((a:T1,...rest:TInit)=>void) extends ((...all: infer AP)=>void) ? AP : never) +// : never, +// 1: [] +// }[T extends []|[any] ? 1 : 0] + +// type TReverse = { +// 0: [], +// 1: ((a:TLast, ...args: TReverse>)=>void) extends ((...all: infer AP) => void) +// ? AP : never +// }[T extends [] ? 0 : 1]; +// type TReverse = T extends [] +// ? [] +// : ((a:TLast, ...args: TReverse>)=>void) extends ((...all: infer AP) => void) +// ? AP : never; + type Apply1ReturnType = P extends [infer T1, infer T2, ...any[]] ? (((...args: P) => void) extends ((first: any, ...rest: infer S1) => void) ? FunctionX : never) : FunctionX0; @@ -74,6 +113,10 @@ export class FunctionX { // FunctionX<[T,...P],[],R> { return null; } + + public flipped(): FunctionX, Tail>, R> { + return null; + } } const f/*: FunctionX0*/ = FunctionX.of(()=>5);