Skip to content

Instantly share code, notes, and snippets.

@tjhv
Created June 16, 2019 01:12
Show Gist options
  • Save tjhv/bab9d974da48bad79f07c08f0cb5c190 to your computer and use it in GitHub Desktop.
Save tjhv/bab9d974da48bad79f07c08f0cb5c190 to your computer and use it in GitHub Desktop.
extension Dictionary where Value: Equatable
{
func allKeys(for value: Value) -> [Key]
{
return self.enumerated().compactMap {
$0.element.value == value ? $0.element.key : nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment