3 ms·
Your implementation is broken for any function that has more than two arguments. const sum3 = curry(( a, b, c ) => a + b + c ) const sum3_10 = sum3( 10 )
by thrttnkrnl 5y ago
Your implementation is broken for any function that has more than two arguments.
const sum3 = curry(( a, b, c ) => a + b + c )
const sum3_10 = sum3( 10 ) // ...
const sum3_10_20 = sum3_10( 20 ) // ...
sum3_10_20( 30 ) // 60
sum3_10_20( 5 ) // 60
One of the points of currying is to be able to fork the partial application of the function at any point.
- goldenkey 5y agoVery good catch, thank you. Here is my take on a better version that fixes the issue: const curry = fn => { const curried = (...a) => a.length >= fn.length ? fn(...a) : curried.bind(undefined, ...a) return curried }