-
-
Save tarunon/bea3c5cd8d0c8f8c2a2ffb5b9c86e748 to your computer and use it in GitHub Desktop.
This file contains 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
protocol A {} | |
struct B: A{} | |
let tuple1: (A, Int) = (B(), 1) | |
let tuple2: (B, Int) = (B(), 1) | |
// let tuple3: (A, Int) = tuple2 // 共変っぽいけどだめ。 | |
let closure1: (A, Int) -> () = { _ in } | |
let closure2: (B, Int) -> () = { _ in } | |
let closure3: (B, Int) -> () = closure1 // 反変。いける。 | |
let tupleClosure1: ((A, Int), Int) -> () = { _ in } | |
let tupleClosure2: ((B, Int), Int) -> () = { _ in } | |
let tupleClosure3: ((B, Int), Int) -> () = tupleClosure1 // Tupleの共変サポートされてないのにここはいけるのか | |
class MyG<T> { | |
var genericsClosure: (T, Int) -> () = { _ in } | |
} | |
let g = MyG<(B, Int)>() | |
g.genericsClosure = tupleClosure1 // Generics型でも動いてる |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment