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 <[email protected]> wrote:
> 
> 
>> On Dec 5, 2016, at 9:17 PM, David Sweeris via swift-evolution 
>> <[email protected] <mailto:[email protected]>> wrote:
>> 
>> 
>>> On Dec 5, 2016, at 8:54 PM, Jay Zhao <[email protected] 
>>> <mailto:[email protected]>> 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

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to