[Wellington-pm] Round-up of last night's meeting

Grant McLean grant at mclean.net.nz
Thu Aug 14 18:02:40 PDT 2014


Hmm, just closed a window and found this half-written email hiding
behind it ...

On Wed, 2014-08-13 at 02:29 +0100, Olly Betts wrote:
> Here is some of the iterator stuff I've found on CPAN when looking
> before:
> 
> Iterator - http://search.cpan.org/dist/Iterator/Iterator.pm
> 
> API: value() gives the next entry, throwing an exception if done.
> Has is_exhausted() and isnt_exhausted() to check for the end.

I'm really not a fan of throwing an exception "if done" - doesn't seem
very Perlish.  Reaching the end of the end of the result set seems like
a boundary condition rather than an exception.  Trying to read *past*
the end of a result set might be worthy of an exception.

> Array::Iterator - http://search.cpan.org/dist/Array-Iterator/lib/Array/Iterator.pm
> 
> API: next() gives the next entry, throwing an exception if done, or
> get_next() if you want undef if done.  Has has_next() to check for the
> end.

I guess at least that give the user the choice of avoiding exceptions.

> Iterator::Simple - http://search.cpan.org/dist/Iterator-Simple/lib/Iterator/Simple.pm
> 
> API: next() (or <$it> or $it->()) gives the next entry or undef if done.

That's starting to look more like Perl :-)

> And based only on the name, I think it's the one Grant would favour.

Hard to fault that logic.

Cheers
Grant



More information about the Wellington-pm mailing list