Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
Created May 7, 2010 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuarthalloway/393215 to your computer and use it in GitHub Desktop.
Save stuarthalloway/393215 to your computer and use it in GitHub Desktop.
; a clojure 1.2 impl for
; http://blogs.tedneward.com/2010/05/06/Code+Kata+Compressing+Lists.aspx
(def group (partial partition-by identity))
(defn runnify
[coll]
(->> (group coll) (map #(vector (count %) (first %)))))
; into pairs
(runnify [4, 4, 4, 4, 2, 2, 2, 3, 3, 2, 2, 2, 2, 1, 1, 1, 5, 5])
; or flattened
(-> [4, 4, 4, 4, 2, 2, 2, 3, 3, 2, 2, 2, 2, 1, 1, 1, 5, 5]
runnify
flatten)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment