Skip to content

Instantly share code, notes, and snippets.

@efremidze
Last active June 17, 2017 00:55
Show Gist options
  • Save efremidze/af6531f461cd252ce1c9c02c827dc98f to your computer and use it in GitHub Desktop.
Save efremidze/af6531f461cd252ce1c9c02c827dc98f to your computer and use it in GitHub Desktop.
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