/** @module type/_experiements.ts */ import { AnyFunction, Concat, ExtractFunctionArguments, ExtractFunctionReturnValue, IsAny, Prepend, Reverse, } from '../helper-types' // // const ff4 = parallel( ( x: number ) => x + 3, () => 'f' ) ( 4 ) // const fff = head( tryThis ) type BooleanSwitch = Test extends true ? T : F type Pipe = { 'next': ( ( ..._: Fns ) => any ) extends ( ( _: infer First, ..._1: infer Next ) => any ) ? PreviousFunction extends void ? Pipe, ExtractFunctionReturnValue > : ReturnType extends ExtractFunctionArguments[0] ? Pipe > : IsAny extends true ? Pipe > : { ERROR: ['Return type ', ReturnType , 'does comply with the input of', ExtractFunctionArguments[0]], POSITION: ['Position of problem for input arguments is at', Fns['length'], 'from the', BooleanSwitch , 'and the output of function to the ', BooleanSwitch], } : never 'done': ( ...args: InitalParams ) => ReturnType, }[ Fns extends [] ? 'done' : 'next' ] type Compose = Pipe, false> declare function pipe ( ...fns: Fns ): Pipe declare function compose ( ...fns: Fns ): Compose // const fffff = ( a: number, b: number ) => a + 1 // const asf = pipe( ( a: number, b: number ): number => a + 1 , ( x ) => x, ( x ) => x, ( x ): string => x , ( b: number ) => 'sf', ( b: string ) => 'sf' ) // const asfa = pipe( // ( a: number, b: number ): number => a + 1 , // ( x: number ): string => `${x}`, // ( x: string ): string => String( x ), // ( x: string ): string => x , ( b: string ) => 'sf', ( b: string ) => 'sf' ) type SubtractList = { // @ts-ignore 'reduce': ( ( ..._: A ) => any ) extends ( ( _: infer A1, ..._1: infer AR ) => any ) ? ( ( ..._: B ) => any ) extends ( ( _: infer B1, ..._1: infer BR ) => any ) ? B1 extends A1 ? SubtractList : A1 : 'ERROR B' : 'ERROR C', 'done': A, 'end': [], }[ B extends [] ? 'done' : A extends [] ? 'end' : 'reduce' ] type asdf4 = SubtractList<[1, 2, 3], [1, 2]> type Partial = Args extends any[] ? F extends ( ( ...args: infer FA ) => infer Return ) ? FA extends [] ? Args extends [] ? F : Return : SubtractList extends [] ? ExtractFunctionReturnValue // maybe error? : ( ...args: SubtractList ) => ExtractFunctionReturnValue : 'P ERROR' : 'no' type pof = Partial< ( a: number, b: string ) => string[], [number]> type NotRequired = {[K in keyof T]?: T[K] } type Curry = { 'a': A extends any[] ? Partial extends ( ( _: infer First, ..._1: infer Rest ) => infer Return ) ? >( a: First, ...args: B ) => Curry>> : 'never' : never 'b': Partial < F, A >, 'c': Partial < F, A >, }[ A extends any[] ? Partial < F, A > extends AnyFunction ? 'a' : 'c' : never ] declare function partial( f: F, ...args: Args ): Partial declare function curry( f: F, ...args: Args ): Curry // const foo = curry( ( a: number, b: number, c: number, d: string ) => 'asdf' , 4 )( 2 )( 2, 'f' )// ( 1 )( 4 )( 'f ' )