A question related to reflection and `data class`’s copy method.
Currently I am have something like this
enum class GeneralModifier {
Less, Normal
}
data class Latte(
val ice: GeneralModifier = GeneralModifier.Normal,
val milk: GeneralModifier = GeneralModifier.Normal
) : Coffee()
And the selection input is
Pair<String, Enum<GeneralModifier>>
, where the first one is the field name, e.g. “ice”
So I do
tem.copy(
ice = if (field == "ice") GeneralModifier.values().first { it == option } else item.ice,
milk = if (field == "milk") GeneralModifier.values().first { it == option } else item.milk
)
Is there a easier way to do the
copy
?