Skip to content

Instantly share code, notes, and snippets.

Created June 7, 2012 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2889179 to your computer and use it in GitHub Desktop.
Save anonymous/2889179 to your computer and use it in GitHub Desktop.
Generating a sequence corresponding to an infinite breadth-first tree traversal
(def atoms '("a" "b" "c"))
(defn get-children [n] (map #(str n %) atoms))
(defn add-layer
([] (add-layer atoms))
([n]
(let [child-nodes (flatten (map get-children n)) ]
(lazy-seq (concat n (add-layer child-nodes))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment