Skip to Content
Higher-Order Perl
book

Higher-Order Perl

by Mark Jason Dominus
March 2005
Intermediate to advanced
600 pages
14h
English
Morgan Kaufmann
Content preview from Higher-Order Perl

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Perl

Beginning Perl

Curtis Ovid Poe
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Minimal Perl

Minimal Perl

Tim Maher
Perl by Example

Perl by Example

Ellie Quigley

Publisher Resources

ISBN: 9781558607019