BIRT 3.7
Written by: Michael Williams
Featured Refcardz: Top Refcardz:
  1. Scrum
  2. Apache Maven 2
  3. Essential MySQL
  4. Node.js
  5. Groovy
  1. jQuery Selectors
  2. Ajax
  3. Java
  4. Spring Config.
  5. Java Concurrency

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
  • 2873
  • 0

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)