I have a question that's been bugging me.
Lists in Scala are covariant (List[+A]
)
Let's say we have these classes:
class A
class B extends A
The map
function of List[B]
takes a function f: B => C
But I can also use a f: A => C
which is a subclass of f: B => C
and it totally makes sense.
What I am currently confused by is that
the map
function should accept only functions that are superclasses of the original function (since functions are contravariant on their arguments), which does not apply in the example I've given.
I know there's something wrong with my logic and I would like to enlightened.