Luke
09/24/2021, 9:19 PM@optics
to modify a data class
. Let's say I have a data class Foo(val list: List<Bar>)
, is there an operator to modify the only element in the list that matches a predicate?Luke
09/24/2021, 9:32 PM@optics
data class Foo(
val list: List<Bar>,
) {
companion object
}
@optics
data class Bar(
val string: String,
) {
companion object
}
I'm looking for something like this:
Foo.list./*find element*/.string.modify(foo, someTransformation)
simon.vergauwen
09/24/2021, 9:50 PMsimon.vergauwen
09/24/2021, 9:53 PMLuke
09/24/2021, 11:15 PMbar
instance instead? I guess I was unclear in what kind of predicate I wanted sorry. In the example I gave, I could write something like:
Foo.list.first { it.startsWith('H') }.string.modify(foo, someTransformation)
Otherwise, I think I can use the links you shared to implement something custom.