Skip to content

Instantly share code, notes, and snippets.

@slightair
Created April 16, 2017 14:16
Show Gist options
  • Save slightair/a0cc38dca2054b0f7d32ae99cae84435 to your computer and use it in GitHub Desktop.
Save slightair/a0cc38dca2054b0f7d32ae99cae84435 to your computer and use it in GitHub Desktop.
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