It is not possible to execute a variational function with an unknown number of arguments.
Where add is a variational function, you can do something like
var add5 = curryN(add, 5); add5(1)(2)(3)(4)(5);
There simply cannot be avoided, because the curries function will continue to return the function until the last argument is received, after which the calculation will be started.
The only other option is to create a way to "short circuit" the arguments and notify the function that the arguments pass. This will require something like
var xadd = curryUntilUndefined(add); xadd(1)(2)(3)(4)(5)(undefined);
Here, undefined signals the end of the variational arguments. I really do not recommend this because of other problems that it may create for you. Not to mention that it is not particularly pleasant to watch.
source share