Skip to content

Instantly share code, notes, and snippets.

@markmo
Created March 12, 2016 01:00
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 markmo/71fc668207b2f9cb2e4d to your computer and use it in GitHub Desktop.
Save markmo/71fc668207b2f9cb2e4d to your computer and use it in GitHub Desktop.
TemplateHelper
/*
* Alternative implementation using a Custom Interpolator.
*
* @param sc StringContext
*/
implicit class TemplateHelper(val sc: StringContext) extends AnyVal {
def t(args: Any*): String = {
val strings = sc.parts.iterator
val expressions = args.iterator
val sb = new StringBuilder(strings.next)
while (strings.hasNext) {
sb append expressions.next
sb append strings.next
}
sb.toString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment