ceddlyburge/johnson-trotter/1.0.0

JohnsonTrotter

Implementation of the Johnson Trotter algorithm.

JohnsonTrotter.first [ "a", "b", "c" ]
    |> JohnsonTrotter.getState
    |> Maybe.map JohnsonTrotter.next
    |> Maybe.andThen JohnsonTrotter.getPermutation
-- [ "a", "c", "b" ]

Step Type

type Step a
= Done
| Next (State a) (List a)

Represents the next permutation, if there is one.

Initiating permutations

first : List a -> Step a

Initialises permutations. The first argument specifies the list that you want to get permutations for.

Iterating permutations

getState : Step a -> Maybe (State a)

Get the State from Step, if there is one.

getPermutation : Step a -> Maybe (List a)

Get the permutation from Step, if there is one.