FPO icon indicating copy to clipboard operation
FPO copied to clipboard

interesting quirk with named currying

Open getify opened this issue 8 years ago • 4 comments

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

getify avatar Aug 28 '17 23:08 getify

Should named curry(..) and curryMultiple(..) restrict each input to only being specified once, the first time?

Yes. Throw otherwise.

gunar avatar Aug 31 '17 17:08 gunar

hmmmm, throw would sort of violate the current design practice of these methods. why is silently ignoring a bad thing?

getify avatar Aug 31 '17 17:08 getify

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 :-)

gunar avatar Aug 31 '17 19:08 gunar

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.

joshburgess avatar May 09 '18 23:05 joshburgess