arrow-optics
arrow-optics copied to clipboard
["Request"] Optics DSL syntax for `FilterIndex`
What version are you currently using?
0.10.4
What would you like to see?
FilterIndex syntax fore the Optics DSL.
The syntax for filterIndex does not exist yet in the DSL. Here is an example on how it’s done for Each and it neighbouring files you can find the same for At & Inde.
The one that is missing in your example would be.
fun <T, S, I, A> Lens<T, S>.filterIndex(ID: FilterIndex<S, I, A>, p: (I) -> Boolean): Traversal<T, A> = this.compose(ID.filter(p))
val lens = MyDomain.listProperty
.filterIndex(ListExtensions.filterIndex()) { index -> index % 2 }
.itemProperty
var myObject = MyDomain()
myObject = lens.modify(myObject) { "modified string" }
Currently this functionality is only achievable by traditionally composing optics
(MyClass.listProperty compose ListExtensions.filterIndex().filter { index -> index % 2 }).itemProperty