How Javascript ‘Currying’ finally has made sense to me

Yuri Bett
1 min readSep 16, 2017

--

Functional programming has a lot of cool concepts and techniques. I was amazed by each one of them when I started studying it.

When I learned currying, I found it cool, but I didn't see any point in using it at first. My thought was, 'Ok, that's cool, but how does it solve my life?'.

Usually, we see very pointless examples, like a function to greet someone:

I wanted some real world examples. And as I already said in previous posts, I came from a Java background, where everything is Object Oriented. Maybe that's your case too. And the comparison I made, that blew up my mind was that we could use currying like a class constructor with parameters, in OO.

Here we have an Object Oriented code, a DAO:

Notice that I must instantiate the object, sending a param (connection)that will be used in every other method. I set this param once, when I 'construct' the class, and then every other method has access to it.

Now here is the same example using currying:

The matter here is not to choose the best option. This is all about preferences. I am used to say that there are two big groups of people in Javascript. The ones who love the OO paradigm, and the ones who love functional programming. And it's always good to understand the best of both worlds.

The whole enlightening came after watching this video by Fun Fun Function :)

--

--

Yuri Bett

Senior Software Engineer | Technical Lead | Technical Writer - I love everything about Javascript, React.js, Next.js, and Node.js