Skip to content

Instantly share code, notes, and snippets.

@kirsteins
Last active January 30, 2018 09:44
Show Gist options
  • Save kirsteins/a08fc56aff5dfb97e3606fd8d0754a52 to your computer and use it in GitHub Desktop.
Save kirsteins/a08fc56aff5dfb97e3606fd8d0754a52 to your computer and use it in GitHub Desktop.
Wrapped Hashable
extension Optional where Wrapped: Hashable {
var hashValue: Int {
switch self {
case .some(let hashable):
return hashable.hashValue
default:
return 0
}
}
}
@kirillyakimovich
Copy link

Sorry to commenting on a 1 year old gist, but it's first in google search so:
What do you think of:
extension Optional where Wrapped: Hashable { public var hashValue: Int { return map { $0.hashValue } ?? 0 } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment