Contravariance: intuition building from first principles by Sophie COLLARD
āļāļąāļ
- āđāļāļĒāđāļāļĢāđāđāļĄāļ·āđāļ 16 āļ.āļ. 2024
- Talk's page ð scala.io/talks...
Description:
Contravariance throws many developers off the first time they run into it. This talk will equip the audience with an intuitive understanding of contravariance and the tools for working out from first principles whether a type parameter should be covariant or contravariant.
The goal of this talk is to help the audience build an intuition for contravariance from first principles, instead of relying on memorised shortcuts such as âinput type parameters tend to be contravariant and output type parameters covariantâ.
This talks is designed for beginner to intermediate Scala developers. Attendees need to be familiar with subtyping and typeclasses. An understanding of covariance would be beneficial but is not required as weâll cover it in the talk.
Weâll begin by working with an Animal type hierarchy and some PetRescue and PetClinic typeclasses. By working out what can be substituted for what, weâll begin building up intuition for covariance and contravariance. Weâll then test this intuition by working through a second example involving JsonDecoder and JsonEncoder typeclasses.