FPO icon indicating copy to clipboard operation
FPO copied to clipboard

Breaking: Make curry accept list of mandatory arguments

Open gunar opened this issue 8 years ago • 1 comments

Hi Kyle, love this lib!

I've thought about this in the past as well.

From that discussion, it seems that it'd be better for named curry to accept the argument names instead of just the number of arguments. This is my experience as well.

Otherwise, we may fall into the following trap. See that we expected 'z' but got 'k'.

 function foo({ x,y,z }) { return x + y + z; }

 var f = FPO.curry( {fn: foo, n: 3} );

 f( {y: "b" } )()( {} )()( {x: "a", k: "c"} );
 // "ab"

I like https://github.com/rjmk/named-curry implementation better. Although more verbose, it's safer and more flexible.

Also, you get "optional arguments" for free.

I'd be willing to write the code, but it is a breaking change.

gunar avatar Jul 17 '17 00:07 gunar

I think there could be merit to this way of doing currying, but I don't think it would be justified to replace the existing currying. This would need to be a new method. Any thoughts on what it should be called? We already have "curry" and "curryMultiple", so maybe something like "curryExpected" or...?

getify avatar Aug 28 '17 23:08 getify