Link Details

Link 55866 thumbnail
User 253983 avatar

By jober
via artfulcode.nfshost.com
Published: Dec 05 2007 / 14:54

Currying, known in Python land as partial application, is a technique in which a function taking multiple arguments composes a function that takes fewer arguments (in most languages, reducing to one, although this is not the case in Python) by partially applying it to given parameters. For example, a function, sum, might be used to compose a new function called "plus_one" by currying it with the value of one. The composed function is not evaluated; it is returned as a function object which may then be applied to other parameters.
  • 15
  • 0
  • 1877
  • 218

Comments

Add your comment
User 204981 avatar

reido56 replied ago:

0 votes Vote down Vote up Reply

The Javascript example doesn't appear to do what the blog says it does. Test code:

function curry(fn, scope) {
var scope = scope || window;
var args = [];
for (var i=2, len = arguments.length; i < len; ++i) {
args.push(arguments[i]);
};
return function() {
fn.apply(scope, args);
};
}
function alertTwoArg(firstArg,secondArg) {
alert(firstArg + ',' + secondArg);
}
var oneCur = curry(alertTwoArg,window,"firsty");
var twoCur = curry(oneCur,window,"secondy");
twoCur();

User 204981 avatar

reido56 replied ago:

0 votes Vote down Vote up Reply

Blog has been updated.

User 253983 avatar

jober replied ago:

0 votes Vote down Vote up Reply

Thanks for pointing out the problem with the function!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (15)



Voters Against This Link (0)