In Scala, I can easily extract values from objects (e.g. tuple) using partial function:
list
.zip(list.reverse)
.foreach{case (x, y) => println(s"$x $y")}
How can I do that in Kotlin? It seems that destructors are supported only for assignments and for loops.
At Kotlin 1.0 use an additional val
declaration:
list.foreach{val (x, y) = it; println(s"$x $y")}
The team says they are already working on that feature (the syntax was reserved) and they hopefully will get it in Kotlin 1.1:
list.foreach{(x, y) -> println(s"$x $y")}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With