Destructuring declaration for Map or any interface with get(String)

Would be nice to have any Object and Map destructuring declaration (Like in TypeScript) translated into

val (name, age) = map

val name = person["name"]!!
val age =  person["age"]!!

Or maybe use val { name, age } = map if it’s needs to be distinguished from componentN destructuring.

1 Like

You can use local delegated properties:

val map = mapOf(
    "name" to "John Doe",
    "age"  to 25

val name: String by map
val age: Int     by map


Would it work for such case as one-line assigning property to local variable?

val { request_id } = result


val request_id = result.request_id