Skip to content

Instantly share code, notes, and snippets.

@chirino
Forked from jstrachan/gist:2035806
Created March 14, 2012 11:27
Show Gist options
  • Save chirino/2035882 to your computer and use it in GitHub Desktop.
Save chirino/2035882 to your computer and use it in GitHub Desktop.
kotlin code:
val builder = HtmlBuilder(usersLocale).useLongDates()
"foo $a bar $b".build(builder)
Creates an anonymous class
class AnonymousTemplate(a: String, b: Foo) : (String, Foo) {
fun toString() = "foo " + a + " bar " + b
inline fun build(out: Appender): Unit {
out.append("foo ")
out.append(a)
out.append(" bar ")
out.append(b)
}
}
val builder = HtmlBuilder(usersLocale).useLongDates()
AnonymousTemplate(a,b).build(builder)
A really smart compiler plugin could just do this to avoid any object construction :)
val builder = HtmlBuilder(usersLocale).useLongDates()
builder.append("foo ")
builder.append(a)
builder.append(" bar ")
builder.append(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment