First off, i like your work! Its really cool to learn fp style without reading through dozens lines of code :).
I know you copied the curry function from a gist comment 馃槃 , i took some time to learn how it works and notices a problem - especially when its used together with reduce
Problem in one sentence: If the curried function is called with too many arguments, it will return a new curried function instead of calling the final function. Also the new curried function will now return again a new curried function for every further attempt.
https://github.com/selfrefactor/rambda/blob/master/modules/curry.js#L4
...
o.length === f.length
...
A basic example (ES6):
const add = curry((n, n2) => n + n2
add(1, 2, 3)
// result: function
// desired: 3
Reduce example:
const add = curry((n, n2) => n + n2)
reduce(add, 0, [1, 2, 3])
// result: function
Reduce calls the add function not only with acc and value, but also with index and array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
- One way to fix it, would be to change
o.length === f.length to o.length >= f.length
- An alternative would be to change the reduce function in the way, that it only calls with acc and value, (Ramda does it like that: http://ramdajs.com/0.23.0/docs/#reduce)
First off, i like your work! Its really cool to learn fp style without reading through dozens lines of code :).
I know you copied the curry function from a gist comment 馃槃 , i took some time to learn how it works and notices a problem - especially when its used together with reduce
Problem in one sentence: If the curried function is called with too many arguments, it will return a new curried function instead of calling the final function. Also the new curried function will now return again a new curried function for every further attempt.
https://github.com/selfrefactor/rambda/blob/master/modules/curry.js#L4
A basic example (ES6):
Reduce example:
Reduce calls the add function not only with acc and value, but also with index and array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
o.length === f.lengthtoo.length >= f.length