The easiest way is math.combinatorics :
user> (require '[clojure.math.combinatorics :as combo]) nil user> (combo/permutations #{"word1" "word2" "word3"}) (("word1" "word2" "word3") ("word1" "word3" "word2") ("word2" "word1" "word3") ("word2" "word3" "word1") ("word3" "word1" "word2") ("word3" "word2" "word1"))
Edit: I did not look at the implementation of math.combinatorics, but there was a lazy version, because the OP asked for some kind of code.
(defn permutations [s] (lazy-seq (if (seq (rest s)) (apply concat (for [xs] (map
source share