Skip to content

Instantly share code, notes, and snippets.

@derrh
Created October 1, 2014 15:49
Show Gist options
  • Save derrh/9913ba7fb1358d1cf963 to your computer and use it in GitHub Desktop.
Save derrh/9913ba7fb1358d1cf963 to your computer and use it in GitHub Desktop.
import UIKit
func +<A,B>(lhs: [A:B], rhs: [A:B]) -> [A:B] {
var dict : [A:B] = [:]
for (key, value) in lhs {
dict[key] = value
}
for (key, value) in rhs {
dict[key] = value
}
return dict
}
let pets = ["henry": "dog", "bella": "hamster"]
let kids = ["Manny": "boy", "Addy": "Girl"]
let all = [pets, kids]
all.reduce([:], combine: +)
@derrh
Copy link
Author

derrh commented Oct 1, 2014

If you hate operator overloading, and there is very good reason to hate it, you can just replace + with a simple function name: addDictionaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment