[swift-evolution] /*Let it be*/ func() -> @discardable Bool {} /*Rather Than*/ @discardableResult func() -> Bool {}

Mike Kluev mike.kluev at gmail.com
Thu Oct 19 08:59:09 CDT 2017


On 19 October 2017 at 08:52, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:

> No, I'm talking about the implicit discardability proposed by Brent, such
> as for all Optional<@discardable T>.
>
> He proposes that the @discardable syntax has a strong motivating advantage
> because it can be extended in a way to mark _types_ so that return values
> of those types are always implicitly @discardable. That is:
>
> @discardable class A { ... }
> // any return value of type A is implicitly discardable
> // what happens if A : Error and I throw A?
>
> class B : A { ... }
> // is any return value of type B also implicitly discardable?


"discardable" only apply to return types, similar to how "inout" only
applies to "parameter types"
(e.g. you can't make "func foo(x: Optional<inout Bool>)"

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171019/84c69956/attachment.html>


More information about the swift-evolution mailing list