Skip to content

Instantly share code, notes, and snippets.

@olafurpg
Last active May 31, 2019 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olafurpg/bf61edc60dcff8744fd02234298b8c10 to your computer and use it in GitHub Desktop.
Save olafurpg/bf61edc60dcff8744fd02234298b8c10 to your computer and use it in GitHub Desktop.
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