[Melbourne-pm] map -- with an iterator

Toby Corkindale toby.corkindale at strategicdata.com.au
Wed Apr 21 22:59:23 PDT 2010

Hey all,
You're all familiar with the map operator, used like so:

   my @results = map { transform $_ } @input;

However I often find that instead of @input, I have $iterator,
where $iterator is an object supporting a ->next method.

What I would like to be able to do is something like:
   my @results = map { transform $_ } $iterator;
and then have map walk through my iterator for me.

Or even better, I'd like to be able to have:
   my $results = map { transform $_ } $iterator;
where $results is an object supporting a ->push or ->add method of some 

Twisting things around, I could see this being more of a feature of 
$iterator.. ie. so you could do:
my @results = $iterator->map(sub { transform $_ });

I wondered if there are any modules floating around that can be used to 
map on top of the $iterators to add things like 'map', 'filter', 
'foreach', etc to them?

ie. So I could go:

my $iterator = Third::Party::Module->foo;
$iterator.foreach(sub { action $_ });

(Who may have been unduly influenced by Scala lists)

More information about the Melbourne-pm mailing list