http://qs321.pair.com?node_id=543943


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

Anonymous Monk,
No, that isn't a better approach. If your iterator is designed to return a list each iteration and an empty list is valid then you will prematurely terminate.

I stand by my statements though I will concede that it would be fair to say that an empty list is usually safe.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: How To: Make An Iterator
by Anonymous Monk on Apr 20, 2006 at 00:09 UTC
    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.
      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