Is there any less-allocative way to do this? Make ...
# getting-started
m
Is there any less-allocative way to do this? Make User mutable?
Copy code
var user = state.user
sendToBackend(diff.mapValues { when (it.key) {
    "name" -> (it.value as String).also { user = user.copy(name = it) }
    "sex" -> ((it.value as Sex).also { user = user.copy(sex = it) }).name
    "birth" -> ((it.value as Calendar).also { user = user.copy(birth = it.time) }.timeInMillis / 1000L).toString()
    else -> throw AssertionError()
} })
😨 1
s
Deconstruct user, assign into variables and do a single copy with variables
👍 1