I'm trying to figure out how to use applyOptional. I've got this:
import monocle.function.all.index
import monocle.macros.{GenLens, Lenses}
import monocle.std.map._
import monocle.syntax.ApplyOptionalOps._
import monocle.function.Index._
val map: Map[Int, String] = Map.empty
val lens = map applyOptional index(4)
But the compiler tells me "Cannot resolve symbol applyOptional." I imported ApplyOptionalOps._ just to confirm that I had the right imports.
ApplyOptionalOps
is the case class with the source object as the parameter, so by importing its companion object one can't access its functions. One shouldimport monocle.syntax.apply._
instead, which extendsApplySyntax
trait containing implicit conversion from generic source object toApplyOptionalOps
as well as some other operation wrappers. In fact, for just this example it the following imports is sufficient: