Unflattening a sequence to sequences of repeating elements (clojure)
clojure
Solution
user> (partition-by identity [1 2 2 3 3 3 4 2 2 1 1 1])
((1) (2 2) (3 3 3) (4) (2 2) (1 1 1))
user> (vec (map vec (partition-by identity [1 2 2 3 3 3 4 2 2 1 1 1])))
[[1] [2 2] [3 3 3] [4] [2 2] [1 1 1]]
Problem
In Clojure, how do you partition a sequence to subsequences of repeating elements? E.g. : ``` [1 2 2 3 3 3 4 2 2 1 1 1] ``` to ``` [[1] [2 2] [3 3 3] [4] [2 2] [1 1 1]] ``` I've been playing around with some examples trying to understand clojure better, and was stuck on this one for some time.