DEV Community

Discussion on: Introduction to Currying in JavaScript

Collapse
tobisgd profile image
TobiSGD

What exactly is the advantage of this? All I can see is the introduction of a bunch of unnecessary context switches, but maybe I am missing something essential here.

Collapse
fischgeek profile image
fischgeek

It's common in functional languages to pass functions to eachother and not data.

Collapse
tobisgd profile image
TobiSGD

That's nice to know, but sadly doesn't answer the question. Why would I do that to my JS code? What are the advantages and do they outweigh the disadvantages of introducing all these context switches?

Thread Thread
fischgeek profile image
fischgeek

Curious, why are you so concerned with "context switches"? A function should only have knowledge of what it has been given.

Being able to pipe functions together is where the power (and fun) comes in! Have a look at F# For Fun and Profit for a reference on thinking functionally.

Also, see what they say specifically about currying.

I know these are referring to a different language, but the baisc principals remain. Hope this helps you! I'll try to come up with some "real-world" examples time permitting. Cheers.