📘 Zip operator Z in Perl 6

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))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s