Documentation for sub cross

Documentation for sub cross, assembled from the following types:

class List

From List

(List) routine cross

sub cross(+@e:&with --> Seq:D)

Computes the cross-product of two or more lists or iterables. This returns a sequence of lists where the first item in each list is an item from the first iterable, the second is from the second given iterable, etc. Every item will be paired with every other item in all the other lists.

say cross(<a b c>, <d e f>).map(*.join).join(",")
# OUTPUT: «ad,ae,af,bd,be,bf,cd,ce,cf␤» 

The cross routine has an infix synonym as well, named X.

say (<a b c> X <d e f>).map(*.join).join(",")
# output is the same as the previous example 

If the optional with parameter is passed, it is used as a reduction operation to apply to each of the cross product items.

say cross([123], [456], :with(&infix:<*>)).join(",");
# OUTPUT: «4,5,6,8,10,12,12,15,18␤» 

The X operator can be combined with another operator as a meta-operator to perform a reduction as well:

say ([123X* [456]).join(",")
# same output as the previous example