So, given the list:
val a:List[Int] = List(1,2,3)
You can do:
a.contains(Option(2))
Returns false. I understand from the following definitions of functions that allowed this to be compiled in general, it was done on purpose:
def contains[A1 >: A](elem : A1) : scala.Boolean = {...}
sealed abstract class Option[+A]() ...
What I don't understand is why is this useful? If it automatically smooths the option before comparing, so the above value returns true, then it can be useful, but since it will always return false.
I ask because it’s easy to forget to expand the Option variable that you pass to List.contains, which leads to a potentially difficult search for errors.
Thank!
source
share