AN
kotlin
class AddingScope {
var accumulator = 0
operator fun Wrap.unaryPlus(): AddingScope {
accumulator += i
return this@AddingScope
}
}
operator fun AddingScope.plus(i: Int) = + i.w
inline class Wrap(val i: Int)
fun adding(c: AddingScope.() -> Unit): AddingScope {
val res = AddingScope()
res.c()
return res
}
val Int.w
get() = Wrap(this)
fun main() {
val a = adding {
+ 1.w + 2 + 3
+ 4.w + 5 + 6
+ 7.w + 8 + 9
}.accumulator
println(a)
}