What is the cleanest way to update (make a copy with a new value of) nested immutable data classes?
ArrowKt allows to simplify like this, but it does require kapt and annotations
Copy code
val a = a.copy(
b = a.b.copy(
c = a.b.c.copy(
d = a.b.c.d.copy(e = "Cumbersome update")
)
)
)
// Using ArrowKt optics
val a = A.b.c.d.e.modify(a) { "Slick update" }
Are there any better alternatives?
c
CLOVIS
04/20/2023, 9:03 AM
To my knowledge, there are no better ways currently. The value class KEEP contains a better way to do it, but it's still just a KEEP.
k
knthmn
04/20/2023, 9:17 AM
There is this library that uses KSP instead of KAPT
https://kopyk.at/
e
Emil Aleborn
04/20/2023, 10:03 AM
Thank you, I'll evaluate my options. 🙏
m
MarinJuricev
04/20/2023, 1:52 PM
If it impacts your judgment on using Arrow and the
@optics
annotation is acceptable to you, Optics has an KSP plugin as well, you aren’t tied to just KAPT