What is the cleanest way to update (make a copy wi...
# getting-started
e
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
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
There is this library that uses KSP instead of KAPT https://kopyk.at/
e
Thank you, I'll evaluate my options. 🙏
m
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
3