+ 8

I can't imagine a useful application for currying.

almost every language accepts more than one parameter in functions. So what is currying good for?

13th Jul 2020, 12:34 PM
Oma Falk
Oma Falk - avatar
11 ответов
+ 7
Quote from https://softwareengineering.stackexchange.com/questions/185585/what-is-the-advantage-of-currying that helped me understand. "In conclusion: currying is good, because it lets you specialize/partially apply functions using a lightweight syntax and then pass these partially applied functions around to higher order function such as map or filter. Higher order functions (which take functions as parameters or yield them as results) are the bread and butter of functional programming, and currying and partially applied functions enable higher order functions to be used much more effectively and concisely."
13th Jul 2020, 12:43 PM
Slick
Slick - avatar
+ 5
Currying is making a function with 1 parameter which usually has more than one. .my Heureka is a kind of currying the addition of three numbers https://code.sololearn.com/cq55VEUeKl5A/?ref=app
13th Jul 2020, 12:40 PM
Oma Falk
Oma Falk - avatar
+ 5
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I will explain in python. Consider this : def add(x) : def inner(y) : return x + y return inner a = add(2) # we have a add function that is not totally applied print(a(3)) # 5 I don't know if you see. Currying is applying partially a function. And that does return a new function. I advsse you learning Haskell ;)
13th Jul 2020, 12:42 PM
Théophile
Théophile - avatar
+ 5
(JS example) Currying comes in handy when you have a function which has multiple args, and you want PARTIAL CALLING of that function.. Consider a function which has 3 args.. function log(a,b,c){ alert(a,b,c); } and after currying you can call this function partially with just one parameter, or making as the default first parameter: curriedLog = _.curry(log) let newLog = curriedLog(new Date()) And when you want to call with the last two parameters you can just say: newLog("Message","Example");
13th Jul 2020, 2:06 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
10th Aug 2020, 7:48 PM
Zachiah sawyer
Zachiah sawyer - avatar
+ 2
Slick u have an example? I read sth. similar but have not ebough background.
13th Jul 2020, 1:53 PM
Oma Falk
Oma Falk - avatar
+ 1
Practical examples for currying. For the map() function we need to pass a function that has a single argument. Of course we could solve the same also with lambdas, or even with default arguments. But partial() is more elegant :) https://code.sololearn.com/cw1f2Si5Rksd/?ref=app https://code.sololearn.com/cBZ8CthiaJ8h/?ref=app
16th Jul 2020, 3:54 AM
Tibor Santa
Tibor Santa - avatar
0
Ok1
14th Jul 2020, 6:15 AM
Nacho Carbonero
Nacho Carbonero - avatar
0
I use currying in Java very often for logging purposes (in almost each tool), so good example Sami Khan
17th Jul 2020, 2:11 AM
Sandra Meyer
Sandra Meyer - avatar
- 1
Am a beginner, any help?
15th Jul 2020, 9:25 AM
Ike
Ike - avatar