casualjavascript / haskell-in-es6

Source for "Haskell in ES6" article series
http://casualjavascript.com
MIT License
285 stars 11 forks source link

currying #9

Open sergiivorobei opened 8 years ago

sergiivorobei commented 8 years ago

Hello guys! Really enjoy what you are doing.

In Haskell every function is curried. Probably you should transform existing functions to support currying? (And in es6 it looks nice))

My implementation is:

function curry(fn, ...initialArgs) {
    const curried = (...args) => {
        if (args.length >= fn.length) {
            return fn(...args);   
        }
        return (...moreArgs) => curried(...[...args, ...moreArgs]);
    }
    return curried(...initialArgs);
};
veggiemonk commented 8 years ago

@kennyx46 looks really neat!! I think I am going to reuse your code... Thanks a lot :smile: