we need to change an attribute that's pretty deep ...
# arrow
f
we need to change an attribute that's pretty deep in a nested structure of immutable data classes, is there no simpler/more elegant way to do this in Kotlin? or do we have to use lenses or whatever?
Copy code
kotlin
        return taxableOrder
            .copy(
                checks = taxableOrder
                    .checks
                    ?.map { taxableCheck ->
                        taxableCheck.copy(selections = taxableCheck
                                .selections
                                ?.map { taxableSelection ->
                                    taxableSelection.copy(taxCategory = TaxableSelection.TaxCategory.HOT_FOOD) //this is really the only thing we want to change
                                }
                        )
                    }
            )
// but we still have to map and copy every step on the way into that nested attribute 🫠
s
I'm still holding out hope for https://youtrack.jetbrains.com/issue/KT-44653
2
a
this is exactly what optics are for! https://arrow-kt.io/learn/immutable-data/
👍 2
arrow 1
mind blown 1
s
@Sam all my prayers go towards a real immutable DSL. Like the Optics DSL but 1st class, and better 😂 Oof all comments are 3+ years old. Has it been that long since this was announced/shared 🤣 Jeez time flies.