An annoying thing about Z
, zip
, and roundrobin
is that they don't allow you to use
lists of differing sizes. I whipped up this custom infix to solve the problem:
multi sub infix:<ZZ> ($a is copy, $b is copy) {
my ($larger, $smaller) = ($a, $b);
if $a.elems != $b.elems {
($larger, $smaller) = ($a, $b) if $a.elems > $b.elems;
my $sc = $smaller.clone;
while $smaller.elems < $larger.elems {
$smaller.push: $sc.head;
$sc.rotate(-1)
}
}
(
do {
$a.elems > $b.elems
?? ( $smaller[] Z $larger[] )
!! ( $larger[] Z $smaller[] )
}
).map( *.flat )
}
I suspect there are smaller alternatives...