Porting Swift 2.2 to Swift 3.0


(Ryan Lovelett) #1

The following code does not compile in Swift 3.0 and it used to compile
in Swift 2.2. I'm pretty sure it is a bug in Swift 3.0, since it used to
work in Swift 2.2, but perhaps it was a bug that it worked in Swift 2.2.

Help?

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)

The before and after code can be seen in this gist.
https://gist.github.com/anonymous/30cfb47de65b37f4a99429e3d0392de8


(Erica Sadun) #2

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

···

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


(Ryan Lovelett) #3

Thank you :pray:

···

On Thu, Jun 23, 2016, at 11:18 PM, Erica Sadun wrote:

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