+ 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?
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."
+ 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
+ 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 ;)
+ 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");
+ 4
https://code.sololearn.com/cu2DKco5Ho8a/?ref=app check this out
+ 2
Slick u have an example?
I read sth. similar but have not ebough background.
+ 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
0
Ok1
0
I use currying in Java very often for logging purposes (in almost each tool), so good example Sami Khan
- 1
Am a beginner, any help?