Cartesian product operations

Factor handbook » The language » Collections » Sequence operations

Factor handbook » The language » Collections » Sequence operations

Prev: | Trimming sequences |

Next: | Deep sequence combinators |

The cartesian product of two sequences is a sequence of all pairs where the first element of each pair is from the first sequence, and the second element of each pair is from the second sequence. The number of elements in the cartesian product is the product of the lengths of the two sequences.

Combinators which pair every element of the first sequence with every element of the second:

Computing the cartesian product of two sequences:

Combinators which pair every element of the first sequence with every element of the second:

cartesian-each ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... )

cartesian-map ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... newelt ) -- ... newseq )

cartesian-find ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ? ) -- ... elt1 elt2 )

Computing the cartesian product of two sequences:

cartesian-product ( seq1 seq2 -- newseq )

cartesian-product-as ( seq1 seq2 exemplar -- newseq )

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.99 x86.64 (2203, heads/master-424edf64aa, Mar 8 2023 13:48:50)