I was struggled to find a real-life example of using curry function and get the benefit of using curry.
When I google curry function I often see the example like
let add = x => y => x + y;
let add10 = add(10);
console.log(add10(20));
I have to say I really don't see the value of using curry in this example.
After reading through the answers in this SO https://stackoverflow.com/questions/113780/javascript-curry-what-are-the-practical-applications I still don't see the benefit of using it.
For example, the highest score answer give an example of converter, but that example can be rewrote without curry as another answer shows.
I also read through the answers What is the advantage of currying? (although the discussion are not confined to javascript) I still get the feeling that the curry version can be rewrote without curry(in js).
So can someone show me the "real" advantage/benefit of using curry in javascript?
--- update 2021.10.22 ---
I want to provide an answer to my own question because now I have a better understanding of curry. But the question was closed so I provide this update as my answer.
Only after I study Ramda, which uses curry function as the basic building block, do me finally appreciate the usefulness of curry.
Reading the articles on the ramda website like Why Curry Helps, Favoring Curry, Why Ramda? showing how to put "function first,data last", we then can chain a group of functions together and get the final version of a function that work on data directly.
So to answer my own question "A real-life example of using curry", the example of the promise chain in to process data in "Favoring Curry" is a very good one (although with async/await it may not to seem too appealing)
To Robert Harvey, can you please not to delete my update this time or let me know how can I answer it ?
for
loop can be rewritten as awhile
loop. Everyif
statement can be rewritten as awhile
loop. Everywhile
loop can be rewritten as agoto
. That doesn't mean they aren't useful.