Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: How To: Make An Iterator

by Anonymous Monk
on Apr 20, 2006 at 00:09 UTC ( #544476=note: print w/replies, xml ) Need Help??


in reply to Re^2: How To: Make An Iterator
in thread How To: Make An Iterator

If your iterator is designed to return a list each iteration and an empty list is valid then you will prematurely terminate.
Uhm, the whole idea with the above is that if you want "a list" from the iterator the iterator returns an array reference, just as you do if you want to return two or more "lists" from a subroutine or have several "lists" in a list or array.

Why on earth would the iterator want to return a list instead of an array reference? That would just make it uncomfortable to use. If you return array references you have a perfectly general, maintainable and safe way to signal exhaustion.

Replies are listed 'Best First'.
Re^4: How To: Make An Iterator
by Limbic~Region (Chancellor) on Apr 20, 2006 at 12:24 UTC
    Anonymous Monk,
    Listen, feel free to do whatever you want with the iterators you build. Feel free to always and forever use the same return type and exhaustion indicator regardless of the situation. I have very rarely found a silver bullet that fits every situation so my tutorial was written from the perspective of flexibility and responsibility.

    Objection noted.

    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://544476]
help
Chatterbox?
[LanX]: 1234567890 1234567890 1234567890
[LanX]: so inserting own whitespace helps, ie. a JS warning on submit could help preventing problems
[LanX]:  last hour of cb doesn't break
[LanX]: 12345678901234- 123456789012345678 901234567890123456 789012345678901234 567890123456789012 345678901234567890 123456789012345678 901234567890123456 789012345678901234 567890123456789012 345678901234567890 123456789012345678 901234567890123456 789012345678901234 567890

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2017-07-24 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (351 votes). Check out past polls.