jkbbwr
09/20/2017, 4:34 PMthing {
a = "test"
b = "wat"
}
diesieben07
09/20/2017, 8:27 PMthing
to have signature fun thing(body: MyBuilder.() -> Unit)
where MyBuilder
has properties a
and b
.jkbbwr
09/20/2017, 9:20 PMstantronic
09/20/2017, 9:40 PMjkbbwr
09/20/2017, 9:43 PMthing {
it[:a] = "wat"
}
stantronic
09/20/2017, 9:56 PMfun buildAThing() {
thing {
"a" equals "test"
"b" equals "wat"
}
}
fun thing(function: Builder.() -> Unit) {
Builder().function()
}
class Builder {
val declarations = mutableListOf<Declaration>()
infix fun String.equals(other: String): Declaration = Declaration(Term(this), Value(other)).apply { declarations.add(this) }
}
class Term(val name: String)
class Value(val value: String)
class Declaration(term: Term, value: Value)
jkbbwr
09/20/2017, 9:56 PMstantronic
09/20/2017, 10:02 PMjkbbwr
09/20/2017, 10:04 PMdiesieben07
09/20/2017, 10:33 PMjkbbwr
09/20/2017, 10:38 PMdiesieben07
09/20/2017, 10:38 PMMap<String, Any?>
.