# PassiveSupport.Stream.permutations

`permutations`

, go back to PassiveSupport.Stream module for more information.
# permutations(enumerable)

## Specs

permutations(Enumerable.t()) :: Stream.t()

Generates a stream of all possible permutations of the given list.

Note: The permutations of enumerables containing 32 items or more will not come back in exactly the order you might expect if you are familiar with the general permutation algorithm. This is because PassiveSupport first renders the enumerable into a map, with keys representing each item's index from the list form of the enumerable. The Erlang VM uses a keyword list to represent maps of 31 and fewer items,and a data structure called a trie to represent maps larger than that. Because of how Erlang enumerates the key-value pairs of this trie, the order in which those pairs are presented is not in incrementing order.

That said, the order *is* still deterministic, all permutations
of the enumerable will be available by the time the stream is done
being processed, and this function scales far more effectively
by generating permutations out of this intermediary map than it would
by generating them out of the equivalent list.

## Examples

```
iex> 1..4 |> permutations |> Enum.take(16)
[
[1, 2, 3, 4],
[1, 2, 4, 3],
[1, 3, 2, 4],
[1, 3, 4, 2],
[1, 4, 2, 3],
[1, 4, 3, 2],
[2, 1, 3, 4],
[2, 1, 4, 3],
[2, 3, 1, 4],
[2, 3, 4, 1],
[2, 4, 1, 3],
[2, 4, 3, 1],
[3, 1, 2, 4],
[3, 1, 4, 2],
[3, 2, 1, 4],
[3, 2, 4, 1]
]
iex> 1..50 |> permutations |> Enum.take(2)
[
[
34, 13, 45, 24, 30, 48, 31, 44, 40, 46,
49, 27, 47, 32, 12, 38, 10, 33, 1, 2, 3,
4, 5, 6, 7, 8, 9, 11, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 25, 26, 28, 29, 35,
36, 37, 39, 41, 42, 43, 50
],
[
34, 13, 45, 24, 30, 48, 31, 44, 40, 46,
49, 27, 47, 32, 12, 38, 10, 33, 1, 2, 3,
4, 5, 6, 7, 8, 9, 11, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 25, 26, 28, 29, 35,
36, 37, 39, 41, 42, 50, 43
]
]
```