πŸ“˜ Zip operator Z in Perl 6

πŸ“˜ Zip operator Z in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


Z is the zip operator. It mixes the content of its two operands like a zipper does. The operator continues mixing while there are enough data in both operands.

The code

@c = @a Z @b;

is equivalent to the following:

@c = ((@a[0], @b[0]), (@a[1], @b[1]), ...);

Consider another example:

my @a = ^5; # A range from 0 to 5 (excluding 5)
my @b = 'a' .. 'e';
say @a Z @b;

It reveals the internal structure of the object that will be created after the Z operation:

((0 a) (1 b) (2 c) (3 d) (4 e))

One thought on “πŸ“˜ Zip operator Z in Perl 6”

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code