Is it possible to do something like this
val list : List<Pair<T,U>> = ...
list.map { a,b -> .... }
Is it possible to do something like this
val list : List<Pair<T,U>> = ...
list.map { a,b -> .... }
This will be possible in Kotlin 1.1.
+1000
I think it will rather look like this (within parentheses):
list.map { (a, b) -> /*...*/ }
Proposal is here: KEEP/destructuring-in-parameters.md at 50194f6068b56a1b05e7ed46a093f28c85622431 · Kotlin/KEEP · GitHub
I was a bit unsure, if it will make into 1.1 (before yole confirmed it will be included), because the proposal says "Status: Under consideration"
and is not implemented in EAP 1.1-M01.
Also: Thanks to Java 8 support in 1.1-M01 it is now possible to use Java 8’s forEach()
and use a BiConsumer
:
mapOf("foo" to 1, "bar" to 2).forEach { key, value ->
println("$key to $value")
}
The implementations in Kotlin 1.1 M01 are prototypes of the functionality described in the KEEPs.
Now I understand when the KEEP proposal says "Prototype: Implemented"
.