Destructuring in lambas


#1

Is it possible to do something like this

val list : List<Pair<T,U>> = ...
list.map { a,b -> .... }

#2

This will be possible in Kotlin 1.1.


#3

+1000


#4

I think it will rather look like this (within parentheses):

list.map { (a, b) -> /*...*/ }

Proposal is here: https://github.com/Kotlin/KEEP/blob/50194f6068/proposals/destructuring-in-parameters.md

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")
}

#5

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".

via: https://blog.jetbrains.com/kotlin/2016/07/first-glimpse-of-kotlin-1-1-coroutines-type-aliases-and-more/