
Have you seen the word "currying" in JavaScript and wondered what it meant? In this blog, we'll look at the concept of currying, break it down with...
For further actions, you may consider blocking this person and/or reporting abuse
You are totally right a curryng is a great tool of JS programming.
Great to put into the table!
But the standard function is a different question.
A way more elegant declaration of currying is a arrow function.
I am using this technic in my program, there you can found the repo link in this post: dev.to/pengeszikra/javascript-grea...
Thanks for the comment!
You are correct, arrow functions are an easier way to write curried functions. They provide clarity and context, making them useful for this purpose.
I appreciate that you included a practical application of currying in your program. It's always interesting to see how theoretical concepts apply to practical implementations. I'll surely check that.
But this example (as is one of the above) isn't really currying, it is a predetermined order and is not reusable - It isn't returning a function that says "add the next argument" it is only returning a series of pre-determined arguments.
If I want to add, say, a layer that is "tomato" and another layer that is "onion" this function breaks.
You totally right this example functions is don't really usefull.
Maybe this is much usefull example, to combine a different dependency
on the right moment.
Currying is usually seen as one of those advanced concepts. Breaking a function into smaller parts definitely improves reusability and clarity. I like it because it eliminates the need to repeatedly pass the same arguments and this makes your code more flexible and more maintainable. Good job!
Thanks for the comment!
Yeah, currying improves reusability and clarity by dividing down functions. It eliminates unnecessary parameters, increasing code flexibility and maintainability.
I'm glad you find it useful.
I am happy to see many devs are shifting from OOP to Functional programming. Please stop using Class and this keywords in JavaScript. Thank me later.
Still many companies ask bind, call and apply uses in interviews. React stopped using Class components too.
There are many cases where a class based system as well as prototypal syntax make more sense, such as games for example. Functional Programming is great for operations on data, but can create code spaghetti chaos instead of organized properties when dealing with private getter/setters. Sometimes you just need encapsulation.
Completly agree with you. Use the right tool for the right problem, OOP for modeling, FP for creating abstractions.
Nice points, everyone! Each approach works in its own context: OOP provides structure and encapsulation, while FP simplifies data operations and abstractions. The important thing is using the appropriate approach for the correct challenge.
The most common and useful case for currying is “configuring” a function that needs a specific signature.
So if you have to provide a call back to an onclick event of a button (which must be (e) => void), but need to pass it arguments first, then currying is brilliant for it.
const configureMyOnClick = (dependency) => (e) => {
If (dependency)
// do a thing.
}
Thank you for sharing the example! You are correct, currying is ideal for such situations. It enables functions to be modified to specific requirements, such as passing dependencies while keeping the necessary signature. A great real-world use case!
This was really one of the best explanation of currying with simple examples... Really liked it!!
Thanks for appreciating
I’m glad you like it.
Great
Thanks for appreciating
Mind-blowing
Thanks for appreciating
I likes this and went to googling more about it and I found... somewhere that marked Currying as Miscellaneous. What is your take on this?
Thank you for your comment!
Currying may be considered "miscellaneous" by some, but I believe it is a useful tool in functional programming. It benefits in applications such as partial application or developing reusable, flexible functions. While it may not be used every day, it is definitely worth learning!
I love the simplicity of your writing... Awesome Content 👏🏻
Thanks for appreciating
Currying is garbage now that Javascript supports classes. You can do anything more manageable with a class. And there is a 1 to 1 syntax change for currying to classes
typescript to es3 converts class to function currying, for example
Just stop with this legacy syntax. Unless you really need to write es3 code