Created
May 7, 2010 09:02
-
-
Save stuarthalloway/393215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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