3 ms·
List::map vs List_map is merely a syntactic difference. That's not the issue. Mutable collections are invariant, immutable collections are covariant. Mutable c
by jules 8y ago
List::map vs List_map is merely a syntactic difference. That's not the issue.
Mutable collections are invariant, immutable collections are covariant. Mutable collections do not support map in the mathematical sense, immutable collections do.
I didn't say that if you map List<A> to List<B> that List<B> is then a subtype of List<A>. That is only the case if A is a subtype of B. Rather, the ability to write map implies that List is covariant, and conversely, covariant types support map.
A type Foo<T> is covariant if T appears only as an output to methods and not as an input to methods. For such types you can implement map(f) by returning a proxy that calls the original object, but whenever a method returns a value v of type T you return f(v) instead.