Last active
August 29, 2015 14:14
-
-
Save RobJDavey/87dcbbb49fbc9556a1ac to your computer and use it in GitHub Desktop.
Add two swift dictionaries together into a new optional dictionary, result is nil if there were conflicting keys
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
func +<Key, Value>(lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value]? { | |
var result = lhs | |
for (key, value) in rhs { | |
if contains(lhs.keys, key) { | |
return nil | |
} | |
result[key] = value | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment