Skip to content

Instantly share code, notes, and snippets.

Created June 24, 2016 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/30cfb47de65b37f4a99429e3d0392de8 to your computer and use it in GitHub Desktop.
Save anonymous/30cfb47de65b37f4a99429e3d0392de8 to your computer and use it in GitHub Desktop.
Port Dictionary extension from Swift 2.2 to Swift 3.0
extension Dictionary {
init<S: SequenceType where S.Generator.Element == Element>(pairs: S) {
self.init()
for (key, value) in pairs {
self[key] = value
}
}
}
let foo = ["Lorem", "ipsum"]
let bar = ["dolor", "sit"]
let baz = zip(foo, bar)
let qux = baz.lazy
.map({ ($0.uppercaseString, $1.uppercaseString) })
Dictionary(pairs: baz)
Dictionary(pairs: qux)
extension Dictionary {
init<S: Sequence where S.Iterator.Element == Element>(pairs: S) {
self.init()
for (key, value) in pairs {
self[key] = value
}
}
}
let foo = ["Lorem", "ipsum"]
let bar = ["dolor", "sit"]
let baz = zip(foo, bar)
let qux = baz.lazy
.map({ ($0.uppercased(), $1.uppercased()) })
Dictionary(pairs: baz)
Dictionary(pairs: qux)
// Fails to compile with the following error: Generic parameter 'Key' could not be inferred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment