Perl6 - not your father's foreach
User:
afbach
Date: 8/2/2012 10:31 am
Date: 8/2/2012 10:31 am
Views: 416
Rating: 0
Rating: 0
...
The Z infix operator version of the zip function allows the parallel
use of two lists. It can be used more than once in a single
expression:
use v6;
my @operator = <+ - *>;
my @left = <1 2 3>;
my @right = <7 8 9>;
for @left Z @operator Z @right -> $a, $o, $b {
say "$a $o $b";
}
gets:
1 + 7
2 - 8
3 * 9
Cool!
http://perl6maven.com/perl6-looping-over-a-list-of-values-one-at-a-time-two-at-a-time-and-more
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk
The Z infix operator version of the zip function allows the parallel
use of two lists. It can be used more than once in a single
expression:
use v6;
my @operator = <+ - *>;
my @left = <1 2 3>;
my @right = <7 8 9>;
for @left Z @operator Z @right -> $a, $o, $b {
say "$a $o $b";
}
gets:
1 + 7
2 - 8
3 * 9
Cool!
http://perl6maven.com/perl6-looping-over-a-list-of-values-one-at-a-time-two-at-a-time-and-more
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk