[swift-evolution] Consolidate Code for Each Case in Enum

Daniel Leping daniel at crossroadlabs.xyz
Sun Jan 8 03:51:53 CST 2017


+1 as for compleax enums it really does get messy. Leave the current
approach in place, though.

I'm not sure the syntax is best though. Maybe we could just open a curly
brace right after the enum case declaration and put the specific function
there. Same way everything out of the braces is considered a _default_ case.

On Sun, 8 Jan 2017 at 14:12 Anton Zhilin via swift-evolution <
swift-evolution at swift.org> wrote:

> It would be nice if for each enum case, there was a computed property
> returning an optional. Then you could do:
>
>
> enum FooBar {
>
>     case foo(Int)
>
>     case bar(Int)
>
> }
>
>
>
> let x = FooBar.foo(42)
>
> x.foo  //=> Optional(42)
>
> x.bar  //=> nil
>
>
>
> This feature has been discussed many times, but each time it was
> considered “out of scope”.
>
>
>>
>
> _______________________________________________
>
> swift-evolution mailing list
>
> 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/20170108/cc29e8e9/attachment.html>


More information about the swift-evolution mailing list