Created
April 16, 2017 14:16
-
-
Save slightair/a0cc38dca2054b0f7d32ae99cae84435 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
import Foundation | |
protocol R { | |
associatedtype V | |
func hoge() -> V | |
} | |
struct R1: R { | |
typealias V = Int | |
func hoge() -> V { | |
return 100 | |
} | |
} | |
struct R2: R { | |
typealias V = Void | |
func hoge() -> V {} | |
} | |
struct S<T> { | |
let value: T | |
} | |
struct C {} | |
struct Session { | |
func response<T: R>(subject: T) -> S<T.V> where T.V: Any { | |
return S(value: subject.hoge()) | |
} | |
func response<T: R>(subject: T) -> C where T.V == Void { | |
return C() | |
} | |
} | |
let r1 = R1() | |
let r2 = R2() | |
let session = Session() | |
session.response(subject: r1) // -> S<Int> | |
session.response(subject: r2) // -> C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment