I'm probably missing something, but why not just do...?
var jp = function(last){
return formatNames2('John', 'Paul', last);
} var jp = function(last){
return formatNames2('John', 'Paul', last);
} var jp = function(last) {
return formatNames2('John', 'Paul', last);
};
var je = function(last) {
return formatNames2('James', 'Earl', last);
};
var lh = function(last) {
return formatNames2('Lee', 'Harvey', last);
};
var c = function(middle, last) {
return formatNames('Clarabelle', middle, last);
};
But I find this cleaner: var jp = formatNames2('John', 'Paul'};
var je = formatNames2('James', 'Earl'};
var lh = formatNames2('Lee', 'Harvey'};
var c = formatNames('Clarabelle'};If anything, it does show that one useful thing about partial application is that you can write a generic function (formatNames) and then make it more specific (formatNames("John")) without repeating yourself.
Using fors and ifs:
var origin = Point(0, 0);
var R = 100;
var result = [];
for (var i : array) {
tmp = distance(array[i], origin);
if (tmp>R) {
result.append(tmp);
}
}
Without currying (nobody would write it that way): var origin = Point(0, 0);
var R = 100;
result = filter( map(array, function (x) { return distance(x, origin); }),
function (x) { return greater(x, R);} );
With currying it almost reads like SQL: var origin = Point(0, 0);
var R = 100;
result = filter( map(array, distance(origin)), greater(R) );
It's useful for functions that you predict will be used many times with one of the arguments the same. Yes, it's just syntactic sugar, but it sometimes makes code clearer (especially when literal function syntax is as verbose as in javascript).I just want to note that in Ramda, because of it's strong insistence on a data-last API (which makes the currying easier), this would be written in this order:
result = filter(greater(R), map(distance(origin), array));
But it's precisely the same idea.