antoniomarin
12/02/2019, 4:30 PMset
or distinct
lists from a list of objects based on their property? Currently I’m looping through each user and adding them one by one to the set
val userEmails = mutableSetOf<String>()
users.forEach {
userEmails.add("Adding unique email: ${it.email}")
}
print(userEmails)
serebit
12/02/2019, 4:34 PMval userEmails = users.map { it.email }.toSet()
antoniomarin
12/02/2019, 4:36 PMdistinct
as well, does anyone knows performance wise whats the difference between the two?Shawn
12/02/2019, 4:39 PMantoniomarin
12/02/2019, 4:40 PMdistinct
to add unique values 🙂Shawn
12/02/2019, 4:42 PMserebit
12/02/2019, 4:43 PMusers.map { it.email }.toSet() // returns Set
users.map { it.email }.distinct() // returns List