Created
July 18, 2013 05:05
-
-
Save hisui/6026838 to your computer and use it in GitHub Desktop.
Dumps object tree to console.
This file contains hidden or 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
import java.io.PrintStream | |
trait TreeDumps[T] { | |
def out:PrintStream | |
def dump_r(node:T, last:Boolean=true, indent:String=" ") { | |
out.println(indent + (if (last) "└" else "├") + describe(node)) | |
val a = children(node) | |
if (a.size > 0) { | |
val indent2 = indent + (if (last) " " else "│ ") | |
a.dropRight(1).foreach(dump_r(_, false, indent2)) | |
dump_r(a.last, true, indent2) | |
} | |
} | |
def describe(node:T):String | |
def children(node:T):Seq[T] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment