Skip to content

Instantly share code, notes, and snippets.

@tail-call
Created January 23, 2020 06:57
Show Gist options
  • Save tail-call/23a85a94886f45d33db1401e84ca064d to your computer and use it in GitHub Desktop.
Save tail-call/23a85a94886f45d33db1401e84ca064d to your computer and use it in GitHub Desktop.
Merging dictionaries in Swift easily (JS-like behavior)
import Cocoa
let a: [String: String] = [
"k1": "a1",
"k2": "a2",
"ka": "a3",
]
let b: [String: String] = [
"k1": "b1",
"k2": "b2",
"kb": "b3",
]
let c = a.merging(b, uniquingKeysWith: { $1 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment