optics-dev / Monocle

Optics library for Scala

Home Page:https://www.optics.dev/Monocle/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TraversalLaws.headOption invalidated for underlying null values

kory33 opened this issue · comments

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.

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.

Hmm I see the rational, I still think using Some(_) is better (since, to me, Option(_) has a connotation of handling nulls), but closing the issue if the law is not seen as invalidated. Thank you for the response anyway!