Skip to content

Instantly share code, notes, and snippets.

@etcetc
Last active October 20, 2015 01:31
Show Gist options
  • Save etcetc/e23123a0a0254a175a77 to your computer and use it in GitHub Desktop.
Save etcetc/e23123a0a0254a175a77 to your computer and use it in GitHub Desktop.
Merge two dictionaries in swift using reduce
let d1 = ["a":"foo","b":"bar"]
let d2 = ["c":"car","d":"door"]
let d3 = d1.reduce(d2) { (var d, p) in
d[p.0] = p.1
return d
}
/* Result is ["b": "bar", "a": "foo", "d": "door", "c": "car"] */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment