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.

Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Variance
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. def &(other: Variance): Variance
  4. def *(other: Variance): Variance
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def cut: Variance

    Map everything below bivariant to invariant.

  8. val flags: Int
  9. 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.

  10. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  11. def isBivariant: Boolean
  12. def isContravariant: Boolean
  13. def isCovariant: Boolean
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. def isInvariant: Boolean
  16. def isPositive: Boolean
  17. def symbolicString: String

    The symbolic annotation used to indicate the given kind of variance.

  18. def toString(): String
    Definition Classes
    Variance → Any

Inherited from AnyVal

Inherited from Any

Ungrouped