YAP6 Operator: The Cross Operator

by Adriano Ferreira

Another article of the series "Yet Another Perl 6 Operator"

Perl 6 provides an operator 'X', the cross operator, which combines its list operands into a sort of cartesian product of these arguments.

1,2 X 3,4        # (1,3), (1,4), (2,3), (2,4)

1,2 X 3,4 X 5,6 # (1,3,5), (1,3,6), (1,4,5), ..., (2,4,6)


Elias Pipping
2007-12-21 06:22:06
^3 X ^3

instead of

0..^3 X 0..^3

would work as well, no?

Ask Solem
2007-12-21 06:52:58
How often do you need this? Wouldn't it be much better to have this in a module?
Adriano Ferreira
2007-12-21 09:35:09
@Elias Pipping: you are absolutely right. ^3 X ^3 is just the same as 0..^3 X 0..^3.
Adriano Ferreira
2007-12-21 09:39:33
@Ask Solem: That will depend on the type of programming you do. The availability of features as core also affects what people feel immediately at easy to add to their code. How many times you've heard people complain that X is a handy module, but that they prefer to not add this as a dependency in their code?
Ask Solem
2007-12-22 16:24:27
@Adriano Ferreira: I meant better as in not having it as an operator, but as a method in a class. It could just as well be in core.