Theortically I know what currying is.
Can anyone tell me the practical use of currying in javascript?
Theortically I know what currying is.
Can anyone tell me the practical use of currying in javascript?
In my opinion what make currying interesting is that it makes easier to compose functions using a pointfree programming style.
You can find more information in this book chapter.
Exactly the same as in every other language, e.g. easy partial application:
function curriedAdd(a) {
return function(b) {
return a + b;
}
}
var xs = [1, 2, 3].map(curriedAdd(2));
Compare this to an uncurried approach:
function add(a,b) {
return a + b;
}
var xs = [1,2,3].map(add.bind(null, 2));
There's nothing super special about JS in this regard.