Every `curry` implementation I’ve met is broken in some way.
Let’s think what `curry` function should do. First: is should implement valid currying. Second: it should keep function name untouched. Third: it should keep function length. Fourth: it should allow to bind `this` after any number of arguments (until last).
Missed name? Expect bugs. Missed length. Expect bugs. Etc.
Not a rocket science, right? Then why every existing curry implementation is broken?
Curry
Ramda
Lodash
functional-js
let sum3 = curry((x, y, z) => {
if (this) {
return [x + y + z, this];
} else {
return x + y + z;
}
});// Cannot assign to read only property ‘name’ of function
omg…
— — — — — — — — — — — — — — — — — — —
Working one?
https://gist.github.com/ivan-kleshnin/00e644470e57d38239c1
Go, check it out yourself.