Skip to content

Instantly share code, notes, and snippets.

@hisui
Created July 18, 2013 05:05
Show Gist options
  • Save hisui/6026838 to your computer and use it in GitHub Desktop.
Save hisui/6026838 to your computer and use it in GitHub Desktop.
Dumps object tree to console.
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