See Original text in context
sub infix:<Z>(** --> Seq) is 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 (1, 2 Z <a b c> Z <+ ->).raku;# OUTPUT: «((1, "a", "+"), (2, "b", "-")).Seq»for <a b c> Z <1 2 3 4> -> [, ]# OUTPUT: «a:1b:2c: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 100, 200 Z+ 42, 23; # 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: «()»