Skip to content

Commit 95da2dc

Browse files
committed
Some consistency, please
1 parent d10de1c commit 95da2dc

4 files changed

+6
-6
lines changed

content/posts/type-variance-explained-to-a-ruby-developer.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ We can also notice that we cannot send `object_array` into `print_age`, because
100100

101101
What can we learn from this? Depending if you read from the array or write to it, the type doesn't behave the same.
102102

103-
## Sources are Covariant
103+
## Sources Are Covariant
104104

105105
Composed types from which you can exclusively read or take stuff are called sources. Examples include `Enumerable` and `Reader`. These become more specific as their type members become more specific. As a result of `Dog` being a subtype of `Animal`, `Enumerable<Dog>` is a subtype of `Enumerable<Animal>`; you can pass an `Enumerable<Dog>` to any method that expects an `Enumerable<Animal>`.
106106

107-
## Sinks are Contravariant
107+
## Sinks Are Contravariant
108108

109109
Sinks are the opposite of sources: they're types to which you can exclusively write or put stuff in. Examples include `Logger` or `Writer`. Perhaps counter-intuitively, these become more specific as their type member become less specific! That means that __`Logger<Animal>` is in fact a subtype of `Logger<Dog>`__ (because `Logger<Animal>` will be able to log for any `Dog` as well.
110110

111-
## Read And Write, Put And Take
111+
## Read and Write, Put and Take
112112

113113
What if a method needs to do both? Read and write, put and take? It would appear that they are at the intersection of covariance and contravariance... and that's exactly right: they're __invariant__. No subtyping is possible.
114114

0 commit comments

Comments
 (0)