Skip to content

Instantly share code, notes, and snippets.

@jeremiegirault
Created March 10, 2016 13:49
Show Gist options
  • Save jeremiegirault/1258323c06c141462647 to your computer and use it in GitHub Desktop.
Save jeremiegirault/1258323c06c141462647 to your computer and use it in GitHub Desktop.
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