module Algorithms.List.BasicOperations.Permutations where
import Algorithms.List.Sorting.InsertionSort
permutations
is a function that enumerates all combinations of permutations of the elements of a given list[^1].
-- | >>> permutations [1, 2, 3]
-- [[3,2,1],[3,1,2],[1,3,2],[2,3,1],[2,1,3],[1,2,3]]
permutations :: [a] -> [[a]]
permutations = sortByCataM (\_ _ -> [False, True])