CHAPTER 6 INFINITE STREAMS
There’s a special interface that we can put on iterators that makes them easier to deal with in many cases. One drawback of the iterators we’ve seen so far is that they were difficult or impossible to rewind; once data came out of them, there was no easy way to put it back again. Later on, in Chapter 8, we will want to scan forward in an input stream, looking for a certain pattern; if we don’t see it, we might want to rescan the same input, looking for a different pattern. This is inconvenient to do with the iterators of Chapter 4, but the variation in this chapter is just the thing, and we will use it extensively in Chapter 8.
What we need is a data structure more like an array or a list. We can make the iterators ...
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.