Closed MasseGuillaume closed 10 years ago
Thanks, @MasseGuillaume! Would you be interested in putting together a puzzler around this (hint, hint)..?
oh and Array(1) == Array(1)
would be my favorite :-)
oh and Array(1) == Array(1) would be my favorite :-)
It's a classic, indeed...what would you suggest as the four possible solutions?
I was thinking of ways in which you could make the comparison slightly less "direct", e.g.:
def eqSeq[T](a: Seq[T], b: Seq[T]) = a == b
But this actually works as expected due to array wrapping:
scala> println(eqSeq(List(1), List(1)))
true
scala> println(eqSeq(Array(1), Array(1)))
true
Any thoughts on that..?
yeah, but adding level of indirection can make it worse:
case class Model(a: Array[Int])
Set(Model(Array(1)), Model(Array(2))).contains(Model(Array(1))) // false
or
Array(1).hashCode // 574628410
Array(1).hashCode // 737168815
Array(1).hashCode // 2106652649
@MasseGuillaume Continue the discussion about the first suggested puzzler at #115? ;-)
it comes with a good explaination http://stackoverflow.com/questions/25372561/how-does-orelse-work-on-partialfunctions