chansek
01/28/2022, 6:19 AMval adminOf = user.roles
.filter { it.isAdmin() }
.map { it.entityId to it.entity }
.toMap()
val serviceProviderOf = user.roles
.filter { it.isServiceProvider() }
.map { it.entityId to it.entity }
.toMap()
Joffrey
01/28/2022, 8:24 AMpartition
instead of filter
if the answer is yesMatteo Mirk
01/28/2022, 12:06 PM.map { it.entityId to it.entity }
.toMap()
can be simplified to
.associate { it.entityId to it.entity }
ephemient
01/28/2022, 12:40 PM.associateBy(
keySelector = { it.entityId },
valueTransform = { it.entity }
)
which doesn't require building a Pair and whose lambdas could be replaced with bound references (e.g. User::entityId
etc.), but that's not really the important part of the question…