Last active
August 29, 2015 14:24
-
-
Save lbeschastny/105502ea94682afff68c 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 flatten-bfs [{:keys [attrs content]}] | |
(loop [ret [] | |
queue (into clojure.lang.PersistentQueue/EMPTY content)] | |
(if (seq queue) | |
(let [{attrs :attrs children :content} (peek queue)] | |
(recur (if (nil? (:v attrs)) | |
ret | |
(conj ret (:v attrs))) | |
(into (pop queue) children))) | |
ret))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment