Click on text below to jump to specific point in the video
What is currying?Currying is what a function doesn't take all of its arguments up front. Instead, it wants you to give it the first argument and then the function returns another function which you are supposed to call with the second argument. And it continues, until all the arguments have been provided and then the function at the end of the chain will be the one which returns the value that you actually want.
Start of demoThis function is not curried. It takes a name, a size and an element and returns a string.
Here is the same function in the curried version.
Calling the function
Remember dragon will take a name and it will return another function which takes a size, which in turn returns a third function which takes an element.
The idea with currying is that your function can pass through the application and gradually receive the arguments that it needs.
Our function is written from the start to be curryable, but every functional library worth its salt has a way of making non-curryable functions curryable.
Using lodash to make the dragon function curryabledragon = _.curry(dragon)
Why is currying useful?
Improving existing code with curryingLet us improve with currying. Video outline created using VideoJots