Skip to content

Instantly share code, notes, and snippets.

@rbrockerhoff
Last active August 29, 2015 14:04
Show Gist options
  • Save rbrockerhoff/c5b2c1ea7a9d3f5b142b to your computer and use it in GitHub Desktop.
Save rbrockerhoff/c5b2c1ea7a9d3f5b142b to your computer and use it in GitHub Desktop.
Must be a Swift bug
extension Dictionary {
mutating func merge <S: Sequence where S.GeneratorType.Element == Element> (seq: S) {
var gen = seq.generate()
while let (key: KeyType, value: ValueType) = gen.next() {
self[key] = value
}
}
}
var dict = [0:0]
let more = [1,2,3]
dict.merge(more) // this should give a syntax error, right? But...
println(dict) // prints [0: 0, 1: 140735543552768, 2: 140735543552768, 3: 140735543552768]
// Update: apparently it matches only against the KeyType, so [KeyType] and [(KeyType, AnyType)] work.
@rbrockerhoff
Copy link
Author

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