Variadic Currying
I have been thinking for a while about how to combine variadic functions with currying.
Here is an idea, which I am sure is already out there but is maybe obscure or unnamed? I have been calling it "zerocurry" - if there are zero arguments: call the function; else: partially apply the arguments.
zerocurry(f)(a)(b, c)() is equivalent to f(a, b, c)
The obvious advantage is that it reconciles currying with variadic functions, whatever that's worth.
Less obviously, in some languages this nicely cleans up boilerplate of doing partial application or closures mutating variables: it works well for passing curried functions into places that expect a callback which takes no arguments, and for composing code that wants to pass values into callbacks with code that instead wants to accumulate those values as one long variadic argument list to call later.
The obvious downside is that we lose the ability to have the function trigger upon consuming the last argument it needs. This makes it useless for callbacks that will receive one or more arguments from their caller. On the other hand, with `compose` and a `call` function, that's solved.
compose(g, f)(...) is equivalent to g(f(...))
call(f) is equivalent to f(...)
So compose(call, zerocurry(f)(a, b)(c, d)) would turn the variadically curried function into a regular partially applied function again - call it with some final argument e and it will execute f(a, b, c, d, e).
Or the language or implementation might make it easy to just efficiently get a partially applied function from the zerocurried function.















