Created
October 1, 2014 15:49
-
-
Save derrh/9913ba7fb1358d1cf963 to your computer and use it in GitHub Desktop.
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
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: +) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you hate operator overloading, and there is very good reason to hate it, you can just replace
+
with a simple function name:addDictionaries
.