Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created July 31, 2019 07:05
Show Gist options
  • Save ch8n/80023820704e04ba6eb3220e4f7c8002 to your computer and use it in GitHub Desktop.
Save ch8n/80023820704e04ba6eb3220e4f7c8002 to your computer and use it in GitHub Desktop.
when object destructing use
data class Contact(val email,val twitter)
data class Person(val contactInfo:Contact,name:String,Phone:Long)
val contact = Contact("[email protected]","twitter@Ch8n2")
val dev = Person(contact,"ch8n",99999999)
# unwrapping level one params
with(contact){
//do anything with email and twitter
...
}
# mutilevel param unwrapping
with(dev){
with(contact){
email
twitter
}
name
phone
or
contact.email
contact.twitter
name
phone
}
or
val ((email, twitter), name, phone) = dev.run{
arrayOf(
contact.email,
contact.twitter,
name,
phone
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment