documentcloud/underscore — pull request #885 by masylum (2012-12-05 17:31:09+00:00)
Title: Added `_.f` function to get short/clever iterators

This pull request includes a function that we miss a lot in underscore. That function works in a similar way to the ruby syntax sugar `&:symbol`. It basically returns a function that will access to a given property or method with optional parameters if needed.

Some examples on how are we currently abusing this function at Teambox:

_.map(hashtags, _.f('toLowerCase'));

_.each(this.views, _.f('toggleCollapse'));

Tasks.isImportant = _.f('get', 'important');

_.each(tasks, _.f('set', {important: false}, {silent: true}));

This enables us to write more functional code:

_.compose(_.uniq, _.flatten, _.map)(tasks, _.f('get', 'watchers'));