Code snippet from Lens manual does not compile
import monocle.Lens
val streetNumber = Lens[Address, Int](_.streetNumber)(n => a => a.copy(streetNumber = n))
Fails compilation with error not found: value n. I wanted to fix that but then I noticed that actually it's somehow already mentioned in lens.md file:
// REPL bug: `error: not found: value n` if I rename _streetNumber to streetNumber
import monocle.Lens
val _streetNumber = Lens[Address, Int](_.streetNumber)(n => a => a.copy(streetNumber = n))
val streetNumber = _streetNumber
But I cannot see this snippet at http://julien-truffaut.github.io/Monocle/optics/lens.html and I blame it on tut:silent:invisible. Also it's not just in REPL - I cannot compile it with scala 2.12.2.
Would be nice to this hidden code instead of current visible one. Spent at least half an hour on that, it's really confusing.
@note I added a test for the snippet you pasted here https://github.com/julien-truffaut/Monocle/blob/522-example/test/shared/src/test/scala/monocle/RegressionSpec.scala#L26-L32
It does work on a normal scala project, as far as I know it only fails in tut and repl
@julien-truffaut Prepared a repository with reproducer: https://github.com/note/monocle-lens-doc-reproducer/blob/master/src/main/scala/com/example/Hello.scala
It fails with Hello2 and compiles without Hello2 - so it matters if streetNumber is just a local variable or rather a class field. Must be some compiler quirk. Taking into account that it's a tutorial and it's hard to predict how users will try it out I think it would valuable to have some info about it in manual.
Thanks for creating this project. I wasn't aware of this problem. It is interesting that Hello2 compiles if you add a type annotation to streetNumber:
object Hello2 {
val streetNumber: Lens[Address, Int] = Lens[Address, Int](_.streetNumber)(n => a => a.copy(streetNumber = n))
}
I don't know what is causing this issue ...
I too can't get official example of nested Map update to compile, neither an answer posted on SO by @julien-truffaut. I can open another issue if need be, but thought of commenting here.
https://stackoverflow.com/q/47786656/839733
I think the problem is exasperated by having the examples module as part of the main project. In order to figure out what minimal plugins and dependencies are required, I need to go through a giant build file with hundreds of lines of code.
@asarkar it seems that someone answered your stackoverflow question