Created
April 29, 2011 12:48
-
-
Save gam/948247 to your computer and use it in GitHub Desktop.
tree pretty printer in clojure - variation
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 print-tree | |
([tree] | |
(print-tree tree "")) | |
([tree prefix] | |
(apply str prefix (first tree) "\n" | |
(map #(print-tree %1 (str prefix "\t")) (rest tree))))) | |
(deftest print-tree-test | |
(is (= (print-tree | |
'(parent | |
(child1) | |
(child2 | |
(grandchild1) | |
(grandchild2))) | |
"parent\n\tchild1\n\tchild2\n\t\tgrandchild1\n\t\tgrandchild2")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment