Created
July 31, 2019 07:05
-
-
Save ch8n/80023820704e04ba6eb3220e4f7c8002 to your computer and use it in GitHub Desktop.
when object destructing use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | |
} | |
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