controls.mapValues {
val ans = EnumSet.noneOf(NotificationTarget::class.java)
if (it.value.pushSwitch.isChecked) ans += NotificationTarget.PUSH
if (it.value.emailSwitch.isChecked) ans += NotificationTarget.EMAIL
ans
}
Thank you, that’s an interesting approach, but too allocationful. There are many of switch pairs, and it’s not great to create extra map for each pair.
o
okkero
04/24/2017, 12:42 PM
If you're worried about the performance of the functional approach, then it might just be better to do it imperatively
✅ 1
okkero
04/24/2017, 12:43 PM
Couldn't you just store the mappings in a top level immutable Map?
okkero
04/24/2017, 12:43 PM
I guess you'd have to do an extra filter, then...hmm
m
miha-x64
04/24/2017, 12:44 PM
I thought about a global immutable map at the very first moment, but then I must tag actual switches somehow. Maybe I’d better stick with the original solution.