documentcloud/underscore — pull request #593 by toots (2012-05-05 17:03:32+00:00)
Title: Asynchronous version of _.reduce

Hi,

I've been in a situation lately where I wanted to use `_.reduce` to chain computations on a collection, but each individual computation was asynchronous (i.e. making a `HTTP` request to get the result).

Thus, I've cooked up the following extension to reduce, that takes an optional `callback` argument and chain the computations through the callbak. Here's an example:

```
var asyncComputation = function (memo, num, index, list, callback) {
// .. Do some asynchronous computation, returning variable "result"
(...)
// Call callback with that result:
callback(result);
};

// Finally, call _.reduce, which picks up the asynchronous version.
_.reduce( [1,2,0,3], asynComputation, 0, function (result) {
console.log(result);
});
```

I don't know if that is something you guys would like in `underscore` but I'm submitting it here in case it case be useful. Also, other functions of the module could have a similar asynchronous version of them..