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

Adrian Zubarev adrian.zubarev at devandartist.com
Tue May 31 14:57:25 CDT 2016


I apologize for the tons of typos I make. :/



-- 
Adrian Zubarev
Sent with Airmail

Am 31. Mai 2016 um 21:55:53, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

I'd actually like to see a change in guard so that I don't need those 
braces. I'd like something more readable like 

| guard cond1 or return nil 
| guard cond2 or throw MyError.IllegalValue 
| guard cond3 or do { ... } 

It may add more cases for the compiler to handle but in all cases I 
used guard so far the block was never really needed. But I think this 
is out of the scope of this thread. 
This is a different topic, because it would create an alternative for a single-expression guard-else-block. ;)

That looks good.  You might want to include more complex expressions just to make it clear that this isn’t limited to literal-returning expressions.  Otherwise I think it covers it.  Thanks for putting this together!  I’ve wanted this for a long time… :)
Is this example enough for you, what do you thing?

// Today:
public struct Character {
      
    private let _pointer: UnsafePointer<Swift.Character>
    public let source: Module.Source
    public var value: Swift.Character {
        return self._pointer.memory
    }
    ...
}

// Rewritten:
public struct Character {
    ...
    public var value: Swift.Character { self._pointer.memory }
    ...
}

-- 
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160531/f584d667/attachment.html>


More information about the swift-evolution mailing list