Skip to content

orangeeli/cooking-curry

Repository files navigation

Build Status Code Climate

Cooking Curry

This is a small project to play around with function currying. The original code can be found here. I've just made a few changes to improve readability:

  1. Replaced the first if for the logical OR ES6 default parameter.
function cook(f, args=[]) {
// args = args || [];
//(...)
}
  1. Removed the context argument. I just wanted to curry the function without thinking about which scope I'm working with.
  2. You'll need node 6 to run this project.
  3. Function Generators and Iterators on tests FTW!

A bit of context

Function Currying is a technique where you can take a function with n arguments and transform it into a series of functions (n to be precise) with arity 1. The technique is named after his creator Haskel Curry, according to Wikipedia. Still have to confirm this with more sources. Haskell has this for free for every function. I'm still trying to figure out a use case for this technique because every use case that I thought I was using Currying, I was actually using Partial Application or just creating a clojure to return a function that has access to that scope.

The difference between partial application and Currying is that with partial application you take a function with n arguments and you transform it into a function with fewer arguments. In javascript this can be achieved, for example, with the bind operator.

As for the clojure example, the use case I had was the handling of the error function when working with Parse's javascript SDK promises. Again, in order to improve code readability, instead of writing the callback function directly as one of the arguments of the then, I wrote something like this

function handleError (res, message) {
  return function (error) {
    res.json(`${message} ${JSON.stringify(error)}`);
  }
};

Still have to figure out a use case for Function Currying, yet in the mean time I have this small project to play around with the technique and understand a little bit more.

Sources

License

MIT License

Follow me (@orangeeli) on Twitter!

About

This is as small playground with the function currying technique

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published