CHAPTER 4 ITERATORS
4.1 INTRODUCTION
An iterator is an object interface to a list.
The object’s member data consists of the list and some state information marking a “current position” in the list. The iterator supports one method, which we will call NEXTVAL. The NEXTVAL method returns the list element at the current position and updates the current position so that the next time NEXTVAL is called, the next list element will be returned.
Why would anyone want an object interface to a list? Why not just use a list? There are several reasons. The simplest is that the list might be enormous, so large that you do not want to have it in memory all at once. It is often possible to design iterators to generate list items as they’re requested, so that ...
Get Higher-Order Perl 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.