Skip to content

Instantly share code, notes, and snippets.

@ch8n
Last active July 30, 2019 07:39
Show Gist options
  • Select an option

  • Save ch8n/7563b02d3aee0f473c6436322cf1e388 to your computer and use it in GitHub Desktop.

Select an option

Save ch8n/7563b02d3aee0f473c6436322cf1e388 to your computer and use it in GitHub Desktop.
Possible destructing options in kotlin
//Data Class Destructuring
val person = Person(1, "Chetan", 25)
val(id, name, age) = person
//Collections Destructuring
//map
val map: HashMap<Int, Person> = HashMap()
map.put(1, person)
map.forEach { entry->
val(key,value) = entry
}
//List or Arrays
val threeItemList = listOf("one", "two", "three")
val (itemOne, itemtwo) = threeItemList
//Destructuring in Lambda
map.forEach { (key,value)-> ...}
//Destructuring in for loop
for ((key, value) in map) { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment