Should kotlin support nested deconstruction?

Could you show a use case where this type of destructuring is clearly needed?

Yes, there is a real-world example. This pain happens with RxKotlin when using withLatestFrom method:

import io.reactivex.rxjava3.kotlin.withLatestFrom

streamOfPairs.withLatestFrom(streamOfValues).subscribe { (pair, z) ->
    val (x, y) = pair
    // ....
},

When we attach an additional stream to the original stream of pairs, we end up with a nested pair that cannot be simply deconstructed anymore.

2 Likes

Yes, lack of nested destructuring was a painful part of the otherwise nice transition from Python to Kotlin. I miss it every day.

2 Likes
  1. Absence of explicit type definition doesn’t lead to absence of static type check.
  2. Destructuirng of any nested data structure becomes pain and namespace bloating in current implementation. The more nesting levels the more pain and bloating.
  3. Almost any enterprise level data model can be relevant example because most of them are deeply nested.
1 Like