-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
At the end of the page on variances the reader has to do a lot of work to figure out the "what does the animal eat example". I think it would be great if it included working code like the previous examples. However, it's a bit confusing in terms of what the "what does an animal eat" function should return. Should it return a type or an instance of animal?
One way to make it more concrete and clear would be to write a function that takes an Animal and a List[Animal] and filters out the ones that cannot be eaten. This way you could show example code that takes a Cat and a list of different animal instances, some of them being mice, and returns a List[Animal] that is clearly containing SmallAnimal.
This way we have shown contravariance and covariance in Function1