final class Variance extends AnyVal
Variances form a lattice:
- Covariant - / \ Invariant Bivariant \ / Contravariant
The variance of a symbol within a type is calculated based on variance annotations, e.g. +A or -A, and the positions of the types in which the symbol appears. The actual mechanics are beyond the scope of this comment, but the essential operations on a Variance are:
'&' - like bitwise AND. Unless all inputs have compatible variance, folding them across & will be invariant. '*' - like multiplication across { -1, 0, 1 } with contravariance as -1. flip - if contravariant or covariant, flip to the other; otherwise leave unchanged. cut - if bivariant, remain bivariant; otherwise become invariant.
There is an important distinction between "isPositive" and "isCovariant". The former is true for both Covariant and Bivariant, but the latter is true only for Covariant.
- Alphabetic
- By Inheritance
- Variance
- AnyVal
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
- def &(other: Variance): Variance
- def *(other: Variance): Variance
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
cut: Variance
Map everything below bivariant to invariant.
- val flags: Int
-
def
flip: Variance
Flip between covariant and contravariant.
Flip between covariant and contravariant. I chose not to use unary_- because it doesn't stand out enough.
-
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
- def isBivariant: Boolean
- def isContravariant: Boolean
- def isCovariant: Boolean
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isInvariant: Boolean
- def isPositive: Boolean
-
def
symbolicString: String
The symbolic annotation used to indicate the given kind of variance.
-
def
toString(): String
- Definition Classes
- Variance → Any