Scala Type System: Parameterized Types and Variances
Why variance
trait Json
trait JsonWriter[-A] {
def write(value: A): Json
}
val shape: Shape = ???
val circle: Circle = ???
val shapeWriter: JsonWriter[Shape] = ???
val circleWriter: JsonWriter[Circle] = ???
def format[A](value: A, writer: JsonWriter[A]): Json =
writer.write(value)Last updated