I have a complicated, immutable data structure that includes simple fields, but also maps and lists in the hierarchy. Maybe I'm just not reading the documentation closely enough, but there doesn't seem to be an easy way to modify the list as a whole without doing some pretty boiler-platey stuff.
For example, say I had foo.bar.list
and I wanted to add an element at index i
to the list. The only way I see to do that is to use the getter to get the current list, do something like
list.subList(0, i) + listOf(newElement) + list.subList(i, list.size)
and pass that to the setter.
Is there something like list.add(index, element)
or list.remove(index)
that you can call inside a lens to modify just the list
part and keep the rest of the structure the same.
Or is there some easy way to do this with the At
, Index
, or Traversal
parts of the Collections DSL that I just don't see?