Vinicius Araujo
01/09/2020, 2:42 PMval users = getUsers().apply {
val tags = <get list of Pair<userid, tag>>
forEach { user ->
user.tags.addAll(tags.filter { it.first == user.id }.map { it.second })
}
}
Kroppeb
01/09/2020, 3:52 PMKroppeb
01/09/2020, 4:30 PMO(#users * #tags)
while this one is O(#users + #tags)
Vinicius Araujo
01/09/2020, 4:48 PMKroppeb
01/09/2020, 4:56 PMVinicius Araujo
01/09/2020, 5:44 PMKroppeb
01/09/2020, 5:59 PMStavFX
01/09/2020, 7:24 PMval userTags = getTags().groupBy(
keySelector = { it.first },
valueTransform = { it.second }
).withDefault { emptyList() }
val users = getUsers().forEach { user ->
user.tags += userTags.getValue(user.id)
}