Re: [swift-users] Swift 4 Strings and flatMap

2017-10-21 Thread Martin R via swift-users
Compare https://bugs.swift.org/browse/SR-1570 : Swift can infer the return type from single-statement closures, but not from multi-statement closures. Therefore in let result = strArr.flatMap { x in return x } the closure type is inferred as (String)-> String, and therefore th

Re: [swift-users] Swift 4 Strings and flatMap

2017-10-21 Thread Ole Begemann via swift-users
On 21.10.17 02:50, Santiago Gil via swift-users wrote: I just ran into a bug after a Swift 4 migration where we expected [String] and got [Character] from a flatMap since flatMap will flatten the String since it's now a collection.  While I understand why flatMap behaves this way now that strin

Re: [swift-users] Re-initializing lazy vars

2017-10-21 Thread Joanna Carter via swift-users
Oops! forgot to add example code for resetting with non-optional public var : public struct TestStruct { private var _description: String? public var description: String { get { return _description ?? "" } set { _description = newValue } } mutati

Re: [swift-users] Re-initializing lazy vars

2017-10-21 Thread Joanna Carter via swift-users
> It just seems so obvious to create-if-nil, and makes it nice to reset stuff > that should be re-created. In my case, after my NSURLSession gets > invalidated, I wanted to set the property to nil, and next time a session was > needed, it would just get created. The only thing I would query wit