caolan/async — Issue #72: forEach with object + key in iterator
Author: Bartvds
Created: 2011-12-15 10:46:06+00:00
State: open

I was editing some code I had written synchronously with underscore.js (aren't we all :), and wanted to swap sync stuff out for some async goodness. But I found a conceptual mismatch: Underscore's ._each() has a function(value, key, list) iterator format, async only has a (value, callback): it's 'missing' the key +list.

Having the hash, key, value inside the iterator is very useful if you need a bit more then just a basic map()-like. Right now the iterator has no way of knowing where in the input collection the current value would fit or what it's key was. Which is fine when you just update the same collection (map() etc), but when you need the key for something else beside the looping it get's ackward.

Now I do a _.keys() and pull that through some other async stuff. It's nearly the same and works but it's not in the spirit of things no? :)