Skip to content

Instantly share code, notes, and snippets.

@rik0
Created February 26, 2011 20:30
Show Gist options
  • Save rik0/845586 to your computer and use it in GitHub Desktop.
Save rik0/845586 to your computer and use it in GitHub Desktop.
(defn tree->seq [tree]
(letfn [(tree->seq-aux
[stack]
(if-let [s (seq stack)]
(let [{:keys [value left right]} (first stack)]
(lazy-seq
(cons value
(tree->seq-aux
(concat (keep identity [left right])
(rest stack))))))
'()))]
(tree->seq-aux [tree])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment