I'm working with `@optics` to modify a `data class...
# arrow
l
I'm working with
@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?
For a more detailed example, let's say I have:
Copy code
@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:
Copy code
Foo.list./*find element*/.string.modify(foo, someTransformation)
s
Yes, there is filterIndex to which you can pass a predicate
l
This would allow me to filter by receiving the index in the predicate, right? Is there a way to receive the
bar
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.