Hello,
I'm new to Monocle (and optics in general) and I experience some difficulties/frustration with nested optional fields.
Imagine I have the following :
case class Bar(maybeStr: Option[String])
case class Foo(maybeBar: Option[Bar])
val barLenser = Lenser[Bar]
val fooLenser = Lenser[Foo]
val _maybeStr = barLenser(_.maybeStr)
val _maybeBar = fooLenser(_.maybeBar)
And I want to focus on the String that is (possibly) in the Bar that is (possibly) inside a Foo.
The less unsatisfying solution I came up with is the following
_maybeBar.modify(_.map(_maybeStr.set(Some("Modified String"))))(myFooInstance)
I'm confident there is a better solution to that quite simple problem, but I'd greatly appreciate if someone here could help me to find it.
Cheers.
Valentin