Skip to content

Instantly share code, notes, and snippets.

@lbeschastny
Last active August 29, 2015 14:24
Show Gist options
  • Save lbeschastny/105502ea94682afff68c to your computer and use it in GitHub Desktop.
Save lbeschastny/105502ea94682afff68c to your computer and use it in GitHub Desktop.
(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