Skip to content

Instantly share code, notes, and snippets.

@olafurpg olafurpg/debug.sc
Last active May 31, 2019

Embed
What would you like to do?
Example using sourcecode and pprint to implement a `debug` function
def debug[T](d: sourcecode.Text[T])(implicit tpe: pprint.TPrint[T], line: sourcecode.Line, file: sourcecode.File): Unit = {
println(s"${file.value}:${line.value} - ${d.source} ${tpe.render}: ${pprint.apply(d.value)}")
}
@main
def main(): Unit = {
val fooMatrix = List.fill(10)("foo").map(List.fill(10)(_))
debug(fooMatrix)
}
// debug.sc:8 - fooMatrix List[List[String]]: List(
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"),
// List("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo")
// )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.