Last active
July 18, 2018 06:15
-
-
Save Sophia-Gold/494851ca5863795ff031b07637fa6992 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
(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