O'Reilly logo

Mastering Javascript Functional Programming : Become skilled with Functional Programming in JavaScript by applying Javascript concepts to real world development problems by Federico Kereki

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Currying with bind()

We can find a solution to currying by using the .bind() method. This allows us to fixate one argument (or more, if need be; we won't be needing that here, but later on, we will use it) and provide a function with that fixed argument. Of course, many libraries (such as Lodash, Underscore, Ramda, and more) provide this functionality, but we want to see how to implement that by ourselves.

Read more on .bind() at https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind -- it will be useful since we'll take advantage of this method more times in this chapter.

Our implementation is quite short but will require some explanation:

const curryByBind = fn =>    fn.length === 0 ? fn() : p => curryByBind(fn.bind(null, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required