Jonathan Scott Duff wrote:

Um ... could we have a zip functor as well?  I think the common case
will be to pull N elements from each list rather than N from one, M
from another, etc.  So, in the spirit of timtowtdi:

	for zip(@a,@b,@c) -> $x,$y,$z { ... }
sub zip (\@:ref repeat{1,}) {
   my $max = max(map { $_.length } @_);
   my $i = 0;
   while ($i < $max) {
       for (@_) {
           yield $_[$i]
       }
       ++$i
   }
   return ( )
}

That prototype syntax is probably obsolete, but I'm not sure
what the current proposal is. It might be better to force scalar
context on the args so that both arrays and array refs can be
zipped.

I really like the idea of using generic iterators instead of
special syntax. Sometimes it seems like we're discussing 6.x
instead of just 6.0.

This iterator is nice too:

sub pairs (\@a, \@b) {
   my $max = max(@a.length, @b.length);
   my $i = 0;
   while ($i < $max) {
       yield @a[$i] => @b[$i];
       ++$i
   }
   return ( )
}

for pairs (@a, @b) {
   print .x, .y
}

- Ken

Reply via email to