I’ve caught myself using this in place of a traditional for loop:
_.each(_.range(count), function(i){
...
});
The disadvantage being creating an unnecessary array of size count.
Still, i prefer the semantics of, for example, .each(.range(10,0,-1), …); when iterating backwards.
Is there any way to do a lazy iteration over range, as with pythons xrange?
Considering the source of underscore.js says the following about
range:I doubt there is a way to do lazy iteration without modifying the source.