[swift-users] Porting Swift 2.2 to Swift 3.0

Erica Sadun erica at ericasadun.com
Thu Jun 23 22:18:39 CDT 2016


> On Jun 23, 2016, at 9:04 PM, Ryan Lovelett via swift-users <swift-users at swift.org> wrote:
> 
> 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)


extension Dictionary {
    init<S: Sequence where S.Iterator.Element == (Key, Value)>(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()) })

print(Dictionary(pairs: baz))
print(Dictionary(pairs: qux))

-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160623/0588a9d8/attachment.html>


More information about the swift-users mailing list