Cooking with javascript? What? 🤷♂️
Currying is a technique, where a function takes several parameters as input and returns a function ...
For further actions, you may consider blocking this person and/or reporting abuse
Hi there and thanks for your article!
In my opinion, this article deserves a little bit more explanations, especially the usefulness of using curried functions.
If I start from your example.
Even though you have successfully curried your function, we can see that the
2
&3
parameters could have been reused. Now if I take this example.We can see that I'm repeating the
2
a lot. What is great about curried functions is that they can be used to compose higher order functions (a higher order function is a function that either takes a function as parameter or returns a new one), and so helping us reuse some parameters that are commons accross function calls.And this is, in my opinion, what makes currying so powerful. Composing functions helps you decrease the needs for repeating common parts of your application.
This is what I was expecting to read!
Thanks for the explanation,I tried to introduce the characteristic of flexibility, although this approach that you said was the most common as to the power of currying.
Another (arguably more important in practical use) aspect of currying is that enforcing a single argument to the final produced function allows for greater automation in the evaluation.
Consider nested function calls or array operations. While currying is less about minimizing side effects (nothing prevents the curried functions from being stateful - in fact one might argue that currying can encourage stateful functions), it is certainly more aligned with a functional paradigm to write, say
arr.filter(isDivisibleByTwo)
overarr.filter((v) => isDivisible(2, v))
.CHALLENGE
Write a function that curries a function. It should take a function as an argument, and return the curried version.
NEXT LEVEL
Now write a function that uncurries a function.
Neat concept, but the readability on it is a bit questionable.
Incrível!!! Awesome, I didn't know that the arrow function could return other arrow function!
Exactly...
Yeah, it's a technique, but why this isn't about minimizing side effects?