📘 Cross-product operator X in Perl 6

📘 Cross-product operator X in Raku

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

X is the cross product operator, which converts the two given lists to a third one containing all the possible combinations of the elements from the original lists.

@c = @a X @b;

This is the same as the following sequence:

@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]));

The length of the two operands can be different (they are N and M in the example above).

Leave a Reply