I've seen the official example of updating a Map
but I'm having trouble with the syntax.
val pod: Lens[Event, Pod] = GenLens[Event](_.`object`)
val metadata: Lens[Pod, Metadata] = GenLens[Pod](_.metadata)
val labels: Lens[Metadata, Map[String, String]] = GenLens[Metadata](_.labels)
I want to update a key "app" in the labels
Map
. But I can't get the following to compile:
(labels.composeOptional(index("app"))).set("whatever")(someLabels)
In fact, this answer by one of the authors of Monacle doesn't compile.
Without having the definition of your Event class, I do not have an exact answer, but following the tutorial and the University example, I am able to update a nested Map with latest version as of this writing, monocle 1.5.0-cats-M1. Be sure to have both the monocle-core and the monocle-macros jars in your project. Then,
Then, following the university example,
I am able to
The major differences from your code above are the use of at() and wrapping of the Department with Some to correspond with an Option return type when accessing using a key to retrieve value from a Map.