I often find myself looking for something to make copying of data-objects easier.
data class User(val name: String, val age: Int)
val updated = user.copy (age = age + 1)
val updated = user.copy {age -> age +1}
val updated = user.copy {it + 1}
val updated = user.copy {(_,_,age,_,_) -> age + 1}
Maybe if copy could accept a runnable with receiver. Or additional componentFunctions updateAge
etc. Or additional constructor taking 1 argument each.
Especially for nested data-classes something like this would be cool:
data class User(val name: String, val lastLogin: Int)
data class Permission(val user: User)
perm = perm.update {
user.update {
lastLogin = now()
}
}
Or
perm = perm.update {
user.lastLogin = now()
}
As you can see Iām not sure what I need exactly, just something to shorten nested statements like this:
perm = perm.copy(user = perm.user.copy(lastLogin = perm.user.lastLogin + 2)
Regards and thanks for your awesome work!