Last active
May 31, 2019 14:11
-
-
Save olafurpg/bf61edc60dcff8744fd02234298b8c10 to your computer and use it in GitHub Desktop.
Example using sourcecode and pprint to implement a `debug` function
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
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