Created
June 22, 2010 23:34
-
-
Save michalmarczyk/449266 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn munge [vs] | |
(if (== 1 (count (first vs))) | |
(reduce into vs) | |
(let [gs (group-by #(% 0) vs)] | |
(map (fn [k v] | |
{:data k :children v}) | |
(keys gs) | |
(->> (vals gs) | |
(map (partial map #(subvec % 1))) | |
(map munge)))))) | |
;;; or keyd by field value, without :data & :children | |
(defn munge [vs] | |
(if (== 1 (count (first vs))) | |
(reduce into vs) | |
(let [gs (group-by #(% 0) vs)] | |
(zipmap (keys gs) | |
(->> (vals gs) | |
(map (partial map #(subvec % 1))) | |
(map munge)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment