documentcloud/underscore-contrib — pull request #32 by raganwald (2013-05-14 14:24:48+00:00)
Title: Proposed: _.call2, _call2flipped, _.mapArgs, and _.mapArgsWith

`_.call2` is a utility-function that subsumes calling, partial application, and currying. You can write:

_.call2(fun, 1, 2)
_.call2(fun, 1)(2)
_.call2(fun)(1, 2)
_.call2(fun)(1)(2)

This facilitates a lot of other combinator writing. `call2flipped` has the same behaviour, but bakes flipping in.

`_.mapArgs` takes a function and returns a version that performs a map on its arguments. Example:

function echo () {
return [].slice.call(arguments, 0);
}
function square (n) { return n * n; }
_mapArgs(echo, square)(1, 2, 3) //=> [1, 4, 9]

`_.mapArgsWith` is the same thing, with its arguments flipped to facilitate partial application of the mapper as a decorator.

These four functions are integral to a post I'm writing about underscore-contrib :-)