Documentation for routine permutations

Documentation for routine permutations, assembled from the following types:

class Any

From Any

(Any) method permutations

Defined As:

method permutations(--> Seq)

Treats the Any as a 1-item list and uses List.permutations on it.

say Any.permutations# OUTPUT: «(((Any)))␤» 

class List

From List

(List) routine permutations

Defined as:

multi sub    permutations($n      --> Seq:D)
multi method permutations(List:D: --> Seq:D)

Returns all possible permutations of a list as a sequence of lists. So

say .join('|'for <a b c>.permutations
# OUTPUT: «a|b|c␤ 
# a|c|b␤ 
# b|a|c␤ 
# b|c|a␤ 
# c|a|b␤ 
# c|b|a␤» 

permutations treats all list elements as distinguishable, so (1, 1, 2).permutations still returns a list of 6 elements, even though there are only three distinct permutations.

The subroutine form permutations($n) is equivalent to (^$n).permutations, so

.say for permutations 3;
# OUTPUT: «0 1 2␤ 
# 0 2 1␤ 
# 1 0 2␤ 
# 1 2 0␤ 
# 2 0 1␤ 
# 2 1 0␤»