How to use monocle to modify a nested map and another field in scala
I'm giving a try to monocle for the first time. Here is the case class : case class State(mem: Map[String, Int], pointer: Int) And the current modification, using standard scala, that I would like to do : def add1 = (s: State) => s.copy( mem = s.mem.updated("a", s.mem("a") + 1), pointer = s.pointer + 1 ) And here is my implementation with monocle val mem = GenLens[State](_.mem) val pointer = GenLens[State](_.pointer) val add2 = (mem composeLens at("a")).modify(_.map(_ + 1)) andThen pointer.modify(_ + 1) Unfortunately, the code is not cleaner… Is there a more concise way ? Can we generate all