Created
March 10, 2016 13:49
-
-
Save jeremiegirault/1258323c06c141462647 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ClientType: Hashable { | |
var fullName: String { get } | |
} | |
extension ClientType { | |
var hashValue: Int { | |
return fullName.hashValue | |
} | |
} | |
func ==<C: ClientType>(lhs: C, rhs: C) -> Bool { | |
return lhs.fullName == rhs.fullName | |
} | |
protocol CompanyType { | |
typealias Client: ClientType | |
var clients: Set<Client> { get } | |
} | |
struct Company<Client: ClientType> { | |
private let _clients: () -> Set<Client> | |
init(clients: () -> Set<Client>) { | |
_clients = clients | |
} | |
var client: Set<Client> { | |
return _clients() | |
} | |
} | |
struct CustomClient: ClientType { | |
let fullName: String | |
} | |
let microsoft = Company { return [ CustomClient(fullName: "Bill Gates") ] } | |
microsoft.client.forEach { | |
print("\($0.fullName)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment