Last active
November 13, 2015 22:13
-
-
Save OneSadCookie/9c8c4bc4c472f2d9c5af 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
let odds = [ "a": 1, "c": 3, "e": 5 ] | |
let evens = [ "b": 2, "d": 4, "f": 6 ] | |
extension Dictionary { | |
func mergeWith(other: [Key: Value]) -> [Key: Value] { | |
var result = self | |
for (k, v) in other { | |
result[k] = v | |
} | |
return result | |
} | |
} | |
let result = odds.mergeWith(evens) |
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
let odds = [ "a": 1, "c": 3, "e": 5 ] | |
let evens = [ "b": 2, "d": 4, "f": 6 ] | |
// likely performs horribly! | |
let result = odds.reduce(evens) { (var d, p) in d[p.0] = p.1; return d } | |
result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment