Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Last active February 3, 2016 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdgeCaseBerg/dc61cb7072edf222b8ea to your computer and use it in GitHub Desktop.
Save EdgeCaseBerg/dc61cb7072edf222b8ea to your computer and use it in GitHub Desktop.
Playing with string contexts and what one could do with them.
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