Created
June 24, 2016 02:58
-
-
Save anonymous/30cfb47de65b37f4a99429e3d0392de8 to your computer and use it in GitHub Desktop.
Port Dictionary extension from Swift 2.2 to Swift 3.0
This file contains 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
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) |
This file contains 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
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