2

Сonsider a simple case:

case class Node(id: String, name: String, children: Seq[Node])

How can i make changes to any depth using Monocle??

I want to add a new Node to the list children if it isn't exist and sometimes change a name. BUT ANY DEPTH. recursively.

  • You need equivalent of a Lens.Plated but I am not sure if monocle ever ended up adding this. Also excuse me but I am failing to see the advantage of using such a lens. I don't believe defining a single layer lens on Node and traversing the Node yourself will be any less performant than using a lens but certainly will be cleaner – sinanspd Jan 21 '20 at 14:59
  • @sinanspd any others ideas how can i make it? without Monocle? i need "copy" in depth. –  Jan 21 '20 at 15:16
  • I was going to suggest combining ```.copy``` with a ```Seq[Node]``` lens but I realized it will get very ugly. You can try asking at the monocle gitter channel. The author of the library frequently checks the channel so he might have an idea. You can also ask about the Plated stuff there – sinanspd Jan 21 '20 at 15:55
  • [Similar question](https://stackoverflow.com/questions/48458245/how-to-efficiently-traverse-recursive-case-class-trees) – y_ug Jan 21 '20 at 17:10

0 Answers0