Z
ErrorsCollection

Z

Synthesised documentation from language/operators

From language/operators

See Original text in context

sub infix:<Z>(**@lists --> Seq:Dis assoc<list>

The Zip operator interleaves the lists passed to Z like a zipper, taking index-corresponding elements from each operand. The returned Seq contains nested lists, each with a value from every operand in the chain. If one of the operands runs out of elements prematurely, the zip operator will stop.

say (12 Z <a b c> Z <+ ->).raku;
# OUTPUT: «((1, "a", "+"), (2, "b", "-")).Seq␤» 
for <a b c> Z <1 2 3 4> -> [$l$r{
    say "$l:$r"
}
# OUTPUT: «a:1␤b:2␤c:3␤» 

The Z operator also exists as a metaoperator, in which case the inner lists are replaced by the value from applying the operator to the list:

say 100200 Z+ 4223;             # OUTPUT: «(142 223)␤» 
say 1..3 Z~ <a b c> Z~ 'x' xx 3;    # OUTPUT: «(1ax 2bx 3cx)␤»

As any other infix operator, it can be used under its full name:

say infix:<Z>(<a b>,<c d>);             # OUTPUT: «((a c) (b d))␤» 

If no argument is given, it will return an empty Seq

say infix:<Z>();                        # OUTPUT: «()␤»