Chapter 14.4. Iterators in JavaScript

Python’s iteration protocol is very useful. It makes it possible to easily handle large data sets that get reduced down to results of a reasonable size. In addition, the itertools module provides a number of extremely convenient functions. If you haven’t checked out itertools in Python, you definitely should.

Or, you can play around with MochiKit.Iter’s extensive implementation of the same functions. To use iteration tools, however, you need to have iterators.

Just as in Python, an iterator in JavaScript will define a next() method that will throw a StopIteration exception when it is done processing. An iterable object will either define an iter() method or use registerIteratorFactory to tell MochiKit ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.