Contravariance とは?
contravariance は、型引数どうしの subtyping が、それらから構築されるジェネリック型に対して逆方向に流れる variance です。関数のパラメータ位置のように、型パラメータが消費されるだけの場合に安全です。より広い入力型を受け取る関数は、より狭い入力を期待する関数の代わりに使えます。
なぜ重要か
contravariance は、一般的な型を受け取るハンドラが、特定の型を受け取るものが必要な場所で使える理由を説明します。callback やコンシューマーを安全に置き換えるうえで不可欠です。
関連ガイド
What Is Covariance?Covariance preserves subtyping direction, so a generic over a subtype is a subtype of the same generic over a…
What Is Variance in Type Systems?Variance describes how subtyping between type arguments carries over to subtyping between the generic types b…
What Is Bounded Quantification?Bounded quantification constrains a generic type parameter to be a subtype of some bound, so code can rely on…