Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created June 22, 2010 23:34
Show Gist options
  • Save michalmarczyk/449266 to your computer and use it in GitHub Desktop.
Save michalmarczyk/449266 to your computer and use it in GitHub Desktop.
(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