Skip to content

Instantly share code, notes, and snippets.

@Sam-Serpoosh
Created July 10, 2013 01:58
Show Gist options
  • Save Sam-Serpoosh/5962892 to your computer and use it in GitHub Desktop.
Save Sam-Serpoosh/5962892 to your computer and use it in GitHub Desktop.
Cool way of swapping pairs in a collection in Clojure!!!
(defn swap-pairs [items]
(into (empty items)
(interleave (take-nth 2 (drop 1 items))
(take-nth 2 items))))
(swap-pairs [1 2 3 4 5 6]) ;=> [2 1 4 3 6 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment