@@ -442,28 +442,39 @@ export interface ICurried {
442442/* tslint:disable */
443443export function uncurry ( arity : number , f : Function ) {
444444/* tslint:enable */
445-
446445 // f may be a function option with None value
447- if ( f == null ) {
448- return null ;
446+ if ( f == null ) { return null ; }
447+
448+ // return (...args) => {
449+ // // In some cases there may be more arguments applied than necessary
450+ // // (e.g. index when mapping an array), discard them
451+ // args = args.slice(0, arity);
452+ // let res = f;
453+ // while (args.length > 0) {
454+ // const curArgs = args.splice(0,1);
455+ // res = res.apply(null, curArgs);
456+ // }
457+ // return res;
458+ // };
459+ switch ( arity ) {
460+ case 2 :
461+ return ( a1 : any , a2 : any ) => f ( a1 ) ( a2 ) ;
462+ case 3 :
463+ return ( a1 : any , a2 : any , a3 : any ) => f ( a1 ) ( a2 ) ( a3 ) ;
464+ case 4 :
465+ return ( a1 : any , a2 : any , a3 : any , a4 : any ) => f ( a1 ) ( a2 ) ( a3 ) ( a4 ) ;
466+ case 5 :
467+ return ( a1 : any , a2 : any , a3 : any , a4 : any , a5 : any ) => f ( a1 ) ( a2 ) ( a3 ) ( a4 ) ( a5 ) ;
468+ case 6 :
469+ return ( a1 : any , a2 : any , a3 : any , a4 : any , a5 : any , a6 : any ) => f ( a1 ) ( a2 ) ( a3 ) ( a4 ) ( a5 ) ( a6 ) ;
470+ case 7 :
471+ return ( a1 : any , a2 : any , a3 : any , a4 : any , a5 : any , a6 : any , a7 : any ) => f ( a1 ) ( a2 ) ( a3 ) ( a4 ) ( a5 ) ( a6 ) ( a7 ) ;
472+ case 8 :
473+ return ( a1 : any , a2 : any , a3 : any , a4 : any , a5 : any , a6 : any , a7 : any , a8 : any ) =>
474+ f ( a1 ) ( a2 ) ( a3 ) ( a4 ) ( a5 ) ( a6 ) ( a7 ) ( a8 ) ;
475+ default :
476+ throw new Error ( "Uncurrying to more than 8-arity is not supported: " + arity ) ;
449477 }
450-
451- const wrap : ICurried = ( ...args : any [ ] ) => {
452- // In some cases there may be more arguments applied than necessary
453- // (e.g. index when mapping an array), discard them
454- let res : any = f ;
455- for ( let i = 0 ; i < arity ; i ++ ) {
456- const accArgs = [ args [ i ] ] ;
457- const partialArity = Math . max ( f . length , 1 ) ;
458- while ( accArgs . length < partialArity ) {
459- accArgs . push ( args [ ++ i ] ) ;
460- }
461- res = res . apply ( null , accArgs ) ;
462- }
463- return res ;
464- } ;
465- wrap . curried = true ;
466- return wrap ;
467478}
468479
469480/* tslint:disable */
@@ -522,7 +533,7 @@ export function partialApply(arity: number, f: ICurried, args: any[]): any {
522533 return ( a1 : any ) => ( a2 : any ) => ( a3 : any ) => ( a4 : any ) => ( a5 : any ) => ( a6 : any ) =>
523534 ( a7 : any ) => ( a8 : any ) => f . apply ( null , args . concat ( [ a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 ] ) ) ;
524535 default :
525- throw new Error ( "Partially applying to get a function with more than 8-arity is not supported: " + arity ) ;
536+ throw new Error ( "Partially applying to more than 8-arity is not supported: " + arity ) ;
526537 }
527538 }
528539}
0 commit comments