FPO
FPO copied to clipboard
interesting quirk with named currying
Just got bitten by this quirk, but not sure if it's a bug or if we should leave it alone... thoughts?
function foo({x,y,z}) {
console.log(x,y,z);
}
var f = FPO.curryMultiple( {fn: foo, n: 3} );
f( {x:1,y:2} )( {x:4,z:3} );
What would you expect that output to be? I expected 1,2,3 since x was already curried in the first call, but the result is that x:4 effectively overrides (re-curries?) the x:1. That was surprising to me and caused me a bug.
Should named curry(..) and curryMultiple(..) restrict each input to only being specified once, the first time?
Partially related to #19
Should named curry(..) and curryMultiple(..) restrict each input to only being specified once, the first time?
Yes. Throw otherwise.
hmmmm, throw would sort of violate the current design practice of these methods. why is silently ignoring a bad thing?
Allow me to use your own arguments:
Just got bitten by this quirk
I expected 1,2,3 since x was already curried in the first call,
That was surprising to me and caused me a bug.
But by all means, do what you will. Honestly, I am not even using FPO :-)
I wouldn't throw. I'd silently ignore OR ignore + print a warning/error in the console to inform users..... but, yes, it doesn't make sense to allow overriding a named arg that you've already passed in.