Last active
February 3, 2016 16:13
-
-
Save EdgeCaseBerg/dc61cb7072edf222b8ea to your computer and use it in GitHub Desktop.
Playing with string contexts and what one could do with them.
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
import play.Logger | |
scala> implicit class LogHelper(val sc: StringContext) extends AnyVal { | |
| def log(args: Any*): Unit = { | |
| Logger.info(sc.s(args:_*)) | |
| println(sc.s(args:_*)) | |
| }} | |
defined class LogHelper | |
scala> log"Hello $hi" | |
Hello hi | |
scala> log"Hello there" | |
Hello there | |
scala> implicit class ErrorHelper(val sc: StringContext) extends AnyVal { | |
| def error(args: Any*): Unit = { | |
| throw new RuntimeException(sc.s(args:_*)) | |
| }} | |
defined class ErrorHelper | |
scala> error"There's a snake in the watering hole" | |
java.lang.RuntimeException: There's a snake in the watering hole | |
at ErrorHelper$.error$extension(<console>:18) | |
... 43 elided |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment