[swift-evolution] What about renaming Optional.map to Optional.mapMe ?

Jay Zhao zhaojianyin at icloud.com
Mon Dec 5 23:35:38 CST 2016


We can make the code condense when the optional is used as a parameter:

	/// Long version
        if let doubleValue = json["taken_at"].double {
            self.createTime = Date(timeIntervalSince1970:doubleValue)
        }
        
        /// Shourt version
        self.createTime = json["taken_at"].double.mapUnwrapped{ Date(timeIntervalSince1970:$0) }



> On 6 Dec 2016, at 13:18, David Sweeris <davesweeris at mac.com> wrote:
> 
> 
>> On Dec 5, 2016, at 9:17 PM, David Sweeris via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> On Dec 5, 2016, at 8:54 PM, Jay Zhao <zhaojianyin at icloud.com <mailto:zhaojianyin at icloud.com>> wrote:
>>> 
>>> What about mapUnwrapped ?
>> 
>> If the name is anything other than “map”, you already have to think of the “special” word. At that point, why not just unwrap it manually?
>> _ = array2?.count
>> vs
>> _ = array2?.map {$0.count}
> Oops, there shouldn’t be a “?" on the last line

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161206/183e4045/attachment.html>


More information about the swift-evolution mailing list