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

Olly Betts olly at survex.com
Tue Aug 12 18:29:23 PDT 2014

On Wed, Aug 13, 2014 at 12:54:58PM +1200, Grant McLean wrote:
> Further to Olly's talk/discussion [...]

Thanks for the interesting and useful (to me at least, but I hope others
also benefited) discussion.

Here is some of the iterator stuff I've found on CPAN when looking

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.

| This module is meant to be the definitive implementation of iterators,
| as popularized by Mark Jason Dominus's lectures and recent book (Higher
| Order Perl, Morgan Kauffman, 2005).

It's not been updated since 2005, which makes me wonder if it's actually
used much - even for a simple module you'd think there would have been
a bug report or documentation enhancement in close to 9 years.

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

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.

I've not looked up the various pointers people gave last night, but
based on the discussion last night, Iterator::Simple's API seems like a
good model (and I'd never want to return undef as a value).

Allowing <$it> to work is perhaps a nice touch, since you can then take
advantage of the special handling of <> in while, so this won't give up
if the iterator returns 0 or "0" (though I think all Xapian's iterators
would actually return an object):

    while (my $x = <$it>) {

Rather than having to write:

    while (defined(my $x = $it->next())) {

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


More information about the Wellington-pm mailing list