txt: ## permutations.md
  permutations
  
  Combined from primary sources listed below.
  
  # [In Any](#___top "go to top of document")[§](#(Any)_method_permutations "direct link")
  
  See primary documentation
  [in context](/type/Any#method_permutations)
  for **method permutations**.
  
  ```raku
  method permutations(|c)
  ```
  
  Coerces the invocant to a `list` by applying its [`.list`](/routine/list) method and uses [`List.permutations`](/type/List#routine_permutations) on it.
  
  ```raku
  say <a b c>.permutations;
  # OUTPUT: «((a b c) (a c b) (b a c) (b c a) (c a b) (c b a))␤»
  say set(1,2).permutations;
  # OUTPUT: «((2 => True 1 => True) (1 => True 2 => True))␤»
  ```
  
  Permutations of data structures with a single or no element will return a list containing an empty list or a list with a single element.
  
  ```raku
  say 1.permutations; # OUTPUT: «((1))␤»
  ```
  
  # [In List](#___top "go to top of document")[§](#(List)_routine_permutations "direct link")
  
  See primary documentation
  [in context](/type/List#routine_permutations)
  for **routine permutations**.
  
  ```raku
  multi        permutations(Int()    $from --> Seq:D)
  multi        permutations(Iterable $from --> Seq:D)
  multi method permutations(List:D:        --> Seq:D)
  ```
  
  Returns all possible permutations of a list as a [`Seq`](/type/Seq) of lists:
  
  ```raku
  .say 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 elements as unique, thus `(1, 1, 2).permutations` returns a list of 6 elements, even though there are only three distinct permutations, due to first two elements being the same.
  
  The subroutine form behaves the same as the method form, computing permutations from its first argument `$from`. If `$from` is not an [`Iterable`](/type/Iterable), coerces `$from` to an [`Int`](/type/Int) and picks from a [`Range`](/type/Range) constructed with `0..^$from`:
  
  ```raku
  .say for permutations 3;
  # OUTPUT:
  # (0 1 2)
  # (0 2 1)
  # (1 0 2)
  # (1 2 0)
  # (2 0 1)
  # (2 1 0)
  ```
  