Last active
December 21, 2016 08:42
-
-
Save ukitaka/dcf69c35eb82e96e44035fa424b670f5 to your computer and use it in GitHub Desktop.
Contravariant?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typealias Contravariant<A> = (A) -> () | |
| class Hoge { } | |
| class Fuga: Hoge { } | |
| let fuga: Fuga = Fuga() | |
| let hoge: Hoge = Hoge() | |
| let fugaC: Contravariant<Fuga> = { _ in } | |
| let hogeC: Contravariant<Hoge> = { _ in } | |
| fuga is Hoge // true | |
| hoge is Hoge // true | |
| fugaC is Contravariant<Fuga> // true | |
| hogeC is Contravariant<Fuga> // false ... not true | |
| func myFunc(_ cf: Contravariant<Fuga>) { | |
| print("OK") | |
| } | |
| myFunc(fugaC) // OK | |
| myFunc(hogeC) // OK ... (°_°) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
weird... I wouldn't have expected myFunc(hogeC) to work....