Raku Books / Perl 6 at a Glance / Operators
List operators
xx repeats the list the given number of times.
say (1, -1) xx 2; # ((1 -1) (1 -1))Like the string x operator, the xx operator
returns an empty list if the number of repetitions is zero or
negative.
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))
CodeBlockPlaceholder5raku-static @c = @a X @b; CodeBlockPlaceholder6raku-static @c = ((@a [0], @b [0]), (@a [0], @b [1]), (@a [0], @b [2]), … (@a [N], @b [0]), (@a [N], @b [1]), … (@a [N], @b [M])); CodeBlockPlaceholder7raku-static my @list = 1 … 10; CodeBlockPlaceholder8raku-static my @back = 10 … 1; ```