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.100 x86.64 (2264, heads/master-a743826db8, Apr 9 2024 19:44:18)