TraversalLaws.headOption invalidated for underlying null values
kory33 opened this issue · comments
Kory | Ryosuke Kondo commented
On Monocle 3.0.0, the following code (Scastie) produces IsEq
with different lhs
and rhs
:
import monocle.law.TraversalLaws
import monocle.Iso
val stringTraversal = Iso.id[String]
println(TraversalLaws(stringTraversal).headOption(null)) // IsEq(None,Some(null))
Simply replacing Option(_)
with Some(_)
should solve this.
Julien Truffaut commented
Hi Kory, thanks for the ticket.
Monocle like most fp libraries don't handle null. In effect, we do as if null didn't exist in scala.
Kory | Ryosuke Kondo commented
Hmm I see the rational, I still think using Some(_)
is better (since, to me, Option(_)
has a connotation of handling null
s), but closing the issue if the law is not seen as invalidated. Thank you for the response anyway!