Methods by type

Combinations & permutations

Full

Generate every k-subset or every ordering of a list.

.combinations yields every subset (order doesn't matter); .permutations yields every ordering (order does). Both are lazy and produced in a deterministic order.

combinations #

.combinations(k) returns every k-element subset, in order.

say (1, 2, 3).combinations(2);
Output
((1 2) (1 3) (2 3))

With no argument it returns subsets of every size, from empty to the whole list.

permutations #

.permutations returns every ordering — n! of them for n elements.

say <a b c>.permutations.elems;
say <a b c>.permutations.map(*.join).sort;
Output
6
(abc acb bac bca cab cba)

Notes #