[swift-evolution] [Pitch] Make `return` optional in computed properties for a single case

Matthew Johnson matthew at anandabits.com
Tue May 31 14:02:37 CDT 2016


> On May 31, 2016, at 1:59 PM, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> +1. This is example *is not* a single expression code block. There are 3 expressions (the condition, the return value in the else block, and the primary return value). 
> 
> The `else` block is a returning single expression block. I can’t show the `guard` example without any returning scope.
> 
> You said it yourself "everywhere in the language“. It’s not “everywhere“ if we would left out `guards` else-returning block.

I was speaking casually and meant “top level code blocks that return a value”.  You are right that I wasn’t totally clear about that.  I replied to your initial post with the clarification I believe is necessary.

> If we’d allow this we could also write:
> 
> func test(boolean: Bool) {
>     guard boolean else {}
>     print("true")
> }
> 
> This is useless and less readable.
> 
> But we already can do this with closures:
> 
> let nop = {} // useless
> 
> switch value {
>    ...
>    default: {}() // do nothing
> }
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> 
> _______________________________________________
> 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/20160531/16eb055f/attachment.html>


More information about the swift-evolution mailing list