VP
Size: a a a
VP
VP
QH
RU
RU
VP
QH
QH
VP
VP
I
val a = 1 + 2 + 3возвращало сумму цифр от 1 до 9, а не от 1 до 3 или кидало ошибку код стайла.
+ 4 + 5 + 6
+ 7 + 8 + 9;
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)
}
VP
I
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)
}
RU
QH
QH
RU
RU
VP