Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Seq[+A] be covariant in A?

How can Seq[+A] be covariant in A if A occurs in contravariant position:

def :+ (elem: A) : Seq[A] ?

As I understand, a method argument type is a contravariant position. What am I missing ?

like image 881
Michael Avatar asked Mar 15 '11 19:03

Michael


1 Answers

That's the use case signature. It is not a real signature, just what you'll usually see in the common use case.

The real signature is:

def :+ [B >: A, That] ( elem : B )(implicit bf : CanBuildFrom[Seq[A], B, That] ) : That

Which, as you see, doesn't even guarantee a Seq return, much less A.

like image 190
Daniel C. Sobral Avatar answered Sep 27 '22 22:09

Daniel C. Sobral