Skip to content

Instantly share code, notes, and snippets.

@tarunon
Last active August 29, 2015 14:24
Show Gist options
  • Save tarunon/d65f7a5946a2d5ae5208 to your computer and use it in GitHub Desktop.
Save tarunon/d65f7a5946a2d5ae5208 to your computer and use it in GitHub Desktop.
Accept type A or B<A>
import Foundation
protocol Type {
typealias Value: Type
}
extension String: Type {
typealias Value = String
}
struct Attribute<T: Type>: Type {
typealias Value = T
let t: T
}
func aFution<T1: Type, T2: Type, V: Type where T1.Value == V, T2.Value == V>(t1: T1, t2: T2) {
}
aFution("a", t2: "b")
aFution(Attribute(t: "a"), t2: "b")
aFution("a", t2: Attribute(t: "b"))
aFution(Attribute(t: "a"), t2: Attribute(t: "b"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment