Last active
August 29, 2020 08:00
-
-
Save tpolecat/7401433 to your computer and use it in GitHub Desktop.
set is not a functor mkay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class Bad(a: Int) { override def equals(a:Any) = true } | |
scala> val f = (n:Int) => Bad(n) | |
scala> val g = (b:Bad) => b.a | |
... | |
scala> Set(1,2,3).map(f andThen g) | |
res2: scala.collection.immutable.Set[Int] = Set(1, 2, 3) | |
scala> Set(1,2,3).map(f).map(g) | |
res3: scala.collection.immutable.Set[Int] = Set(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm just saying that equals = true breaks https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21