Check this video https://www.youtube.com/watch?v=xw5SJZnTWp4&t=224s
i noticed while trying this code which can help make a function to support currying, notice line 6 where return have (), without parentheses this code does not have capability to return a executable curried function
const addUncurried = (a, b) => a + b;
const curry =
(targetFunction, collectedArguments = []) => {
return (...currentArguments) => {
return (allArguments => {
return (
allArguments.length >= targetFunction.length
? targetFunction(...allArguments)
: curry(targetFunction, allArguments)
)
})([
...collectedArguments,
...currentArguments,
])
}
}
const addCurried = curry(addUncurried);
const increment = addCurried(2); // 6
console.log('increment',increment(4));
console.log('addCurried',addCurried(1,4)); // 5
console.log('addCurried',addCurried(1)(3)); // 4