[swift-evolution] Operators on optional values

Cao Jiannan frogcjn at 163.com
Mon Feb 15 21:57:53 CST 2016


Hi Craig,

From the first email on that subject:
> So things like:
> 
> let n : Int? = 5
> 
> let r = n + 5
> 
> would actually compile as 
> 
> let r = n.map {$0 + 5}

Yes, this is my expect.

Thanks!
I’ll read through that subject later.


> 在 2016年2月16日,11:44,Craig Cruden <ccruden at novafore.com <mailto:ccruden at novafore.com>> 写道:
> 
> There is a thread on this (if I understand correctly):
> 
> 	Subject : Brainstorming: Optional sugar inferred map
> 
>> On 2016-02-16, at 10:40:48, Cao Jiannan via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hi all,
>> 
>> I want to discuss some problems on using operator on optional values.
>> 
>> Here is my code:
>>> 
>>> let value: Bool? = false
>>> 
>>> let result = !value  // the variable ‘result' is expected Optional<Bool> type,
>>>                            // if value is nil, then the result should be nil
>>>                            // otherwise it returns the result of NOT operator.
>> 
>> This cannot work with Swift 2.1.
>> 
>> 
>>> let value: Int? = 0
>>> 
>>> let result = value + 1 // the variable ‘result' is expected Optional<Int> type
>>>                                // if value is nil, then the result should be nil
>>>                                // otherwise it returns the result of NOT operator.
>> 
>> This is also cannot work with Swift 2.1.
>> 
>> If the basic value operator can work with optional types, it will save multiple lines in out code.
>> 
>> Thanks!
>> 
>> Jiannan, Cao
>> 
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160216/306b4e33/attachment.html>


More information about the swift-evolution mailing list