Last active
June 17, 2017 00:55
-
-
Save efremidze/af6531f461cd252ce1c9c02c827dc98f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 +=<K, V>(left: inout [K : V]?, right: [K : V]?) { | |
right?.forEach { left?[$0] = $1 } | |
} | |
func +<K, V>(left: [K : V]?, right: [K : V]?) -> [K : V]? { | |
guard let left = left else { return right } | |
guard let right = right else { return left } | |
return left.reduce(right) { dict, pair in | |
var dict = dict | |
dict[pair.0] = pair.1 | |
return dict | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment