Skip to content

Instantly share code, notes, and snippets.

@Sophia-Gold
Last active July 18, 2018 06:15
Show Gist options
  • Save Sophia-Gold/494851ca5863795ff031b07637fa6992 to your computer and use it in GitHub Desktop.
Save Sophia-Gold/494851ca5863795ff031b07637fa6992 to your computer and use it in GitHub Desktop.
(defn collapse
"Collapses a tree of nested collections
into a vector indexed by depth
in the original structure."
[tree]
(loop [flat (transient [])
tree tree]
(if (empty? tree)
(persistent! flat)
(recur (conj! flat
(filterv (not (coll?))))
(filterv coll? tree)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment