Last active
January 30, 2018 09:44
-
-
Save kirsteins/a08fc56aff5dfb97e3606fd8d0754a52 to your computer and use it in GitHub Desktop.
Wrapped Hashable
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
extension Optional where Wrapped: Hashable { | |
var hashValue: Int { | |
switch self { | |
case .some(let hashable): | |
return hashable.hashValue | |
default: | |
return 0 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 } }