Created
December 11, 2015 17:30
-
-
Save DeFrenZ/06d393c69f1659df65b9 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 Foo: Hashable { | |
var id: Int { get } | |
} | |
extension Foo { | |
var hashValue: Int { return id } | |
} | |
extension Int: Foo { | |
var id: Int { return self } | |
} | |
class Manager { | |
func update <T: Foo> (t: T) { | |
print(t) | |
} | |
func callFoo <T> (v: T) { | |
print("call on", v, T.self) | |
switch v { | |
case is Foo: update(v) | |
case is SequenceType where Generator.Element: Foo: v.forEach { self.update($0) } | |
default: break | |
} | |
} | |
} | |
let m = Manager() | |
m.callFoo("a") | |
m.callFoo(1) | |
m.callFoo(["a"]) | |
m.callFoo([1, 2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment