y
12/11/2025, 9:29 AMclass with a lot of state, and you would like to clone it and only change one val - how should this be done? are you expected to make it into a data class and use the generated copy impl?
or move all the state into a private primary constructor?
or...?galex
12/11/2025, 9:35 AMdata class and using copy() is the right way to do ity
12/11/2025, 9:42 AMdata class is in no way an indication of the class being a "plain old data" - it's just opt-in for the various derived impls such as copy and toString?Jack Boswell
12/11/2025, 9:42 AMMichael Krussel
12/11/2025, 2:16 PMcopy function to any class you want.Coty Saxman
12/11/2025, 4:13 PMval, and it's always the same val, you can add a method to the class that creates a new instance with only the one modification, copying the rest.
One example of where this is useful is when running simulations, like the Game of Life. I add a method called getNextState() in order to make a new instance that has many copied values and a small subset of changed values.
I have a hunch that this might be closer to what you're looking for!Michael Krussel
12/11/2025, 4:16 PMSeri
12/11/2025, 5:21 PMfun YearMonth.minusMonth(): YearMonth
https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/kotlinx.datetime/minus-month.html