Java Reference
In-Depth Information
A General Curry Function
In the last example, we hard coded the multiplier() function so that it could be cur-
ried. It's possible to use a curry() function to take any function and allow it to be par-
tially applied. The curry function is the following:
function curry(func) {
var fixedArgs = [],1);
return function() {
args = fixedArgs.concat([]
return func.apply(null, args);
This can now be applied to a more standard divider() function that returns the result of
dividing its two arguments:
function divider(x,y) {
return x/y;
<< 2
The curry() function can be used to create a more specific function that finds the recip-
rocal of numbers:
reciprocal = curry(divider,1);
<< function () {
args = fixedArgs.concat([]
return func.apply(null, args);
<< 0.5
Search WWH ::

Custom Search