I can modify Map using focus
and index
just fine. Is there a similar functionality in Monocle to update a sequence at given index?
import monocle.syntax.all._
case class C(member: Int)
val map = Map(0 -> C(0), 1 -> C(1))
case class MapContainer(seq: Map[Int, C])
val containedMap = MapContainer(map)
containedMap.focus(_.seq).index(0).replace(C(10)) // works fine
val seq = IndexedSeq(C(0), C(1), C(2))
case class Container(seq: IndexedSeq[C])
val containedSeq = Container(seq)
containedSeq.focus(_.seq).index(0).replace(C(10)) // does not compile
The error is Could not find an instance of Index[IndexedSeq[C],Int,A1]
.
Is such functionality available for Monocle? I was using Quicklens previously and it used at
for both maps and sequences. Unfortunately Quicklens Scala 3 support is not very good at this point, therefore I am exploring alternatives.