[swift-evolution] Proposal: Replace ?? by an (optional) argument to ?

Amir Michail a.michail at me.com
Fri Jan 29 07:41:06 CST 2016


> On Jan 29, 2016, at 5:03 AM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
> 
> I agree with Erica. The ?? operator is very readable IMO.
> 
> Furthermore x?(false).isEmpty looks like it would evaluate false.isEmpty when x is nil which is certainly not what is intended.

What about this then: ??(false, x?.isEmpty)

> In addition it would not be clear which default should be used in case of multiple optional chainings happening, i.e. what should be the result of person?(false).address?.(true).isEmpty
> 
> -Thorsten
> 
> 
> Am 26. Januar 2016 um 03:29 schrieb Erica Sadun via swift-evolution <swift-evolution at swift.org>:
> 
>> Not loving this. I'm quite happy with ??-coalescing and don't see
>> a compelling reason it needs to be "cleaner". I find your suggested
>> enhancement less readable. Looks like an optional chaining across 
>> a function.
>> 
>> -- E
>> 
>>> On Jan 25, 2016, at 7:03 PM, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Examples:
>>> 
>>> * instead of x ?? false, you would have x?(false)
>>> * instead of x?.isEmpty ?? false, you would have x?(false).isEmpty
>>> 
>>> I think this change would result in cleaner looking code.
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160129/13e9bfb2/attachment.html>


More information about the swift-evolution mailing list