If f :: a -> b -> c is curried then uncurry(f) can be defined as:
uncurry :: (a -> b -> c) -> ((a, b) -> c)
I'm trying to implement the above function in javascript. Is my below implementation correct and generic enough or are there are any better solution?
const uncurry = f => {
if (typeof f != "function" || f.length == 0)
return f;
return function()
{
for (let i = 0; i < arguments.length; i++){
f = f(arguments[i]);
}
return f;
};
}
const curry = f => a => b => f(a, b);
const curriedSum = curry((num1, num2) => num1 + num2);
console.log(curriedSum(2)(3)); //5
console.log(uncurry(curriedSum)(2, 3)); //5