5

Following does not work:

val t: Traversable[Int] = Seq(0, 1, 2)

t contains 0

Even changing Traversable to Iterable does not help. One needs to use Seq, or t exists (_ == 0).

When checking the implementation, contains is implemented in SeqLike as follows:

def contains[A1 >: A](elem: A1): Boolean = exists (_ == elem)

As exists is already implemented for Traversable, why not contains?

Suma
  • 33,181
  • 16
  • 123
  • 191
  • 2
    Its variance. See this one - http://stackoverflow.com/questions/2925765/why-does-iterator-have-a-contains-method-but-iterable-does-not-in-scala-2-8 – jacks Nov 25 '16 at 09:44

0 Answers0