documentcloud/underscore — pull request #1132 by brigand (2013-05-30 07:33:26+00:00)
Title: _.lambda function shortcut

I find my self writing a lot of anonymous functions for accessing properties. `pluck` helps with this a little, but in some cases it's not practical. This also has the benifit of converting functions to work as Underscore iterator. Essentially it does the following.

// old way
_.map(obj, function(o){ return o.prop.method(); }
// new way
_.map(obj, _.lambda("prop.method()");

It also allows adding data, which for ease-of-use is sent to all functions called in the `prop` parameter (this is rarely a problem considering most people will call only one function).

Sorting becomes easier.

```
_.sortBy([
{score: 50},
{score: 93},
{score: 31},
], _.lambda('score')
```

Is this really a word? Remember **i** before **e** except after **c**.

```
var word_tests = [
/[aeiou]/gi,
/^[A-Za-z-]+$/,
/^(?!.*([^c])ei)/
];

var userInput = "pneil";
var verdict = _.all(word_tests, _.lambda("test()", userInput));
```