[swift-evolution] Proposal: enum labels for switch cases

Amir Michail a.michail at me.com
Mon Feb 1 18:10:37 CST 2016


> On Feb 1, 2016, at 7:03 PM, Howard Lovatt <howard.lovatt at gmail.com> wrote:
> 
> Isn't that just a nested enum:
> 

It’s not nested. You can still put all the cases in one switch and ignore the labels if you want to.

>     enum X {
>         case L1: L1Type
>         case L2: L2Type
>         enum L1Type {
>             case A, B, C
>         }
>         enum L2Type {
>             case D, E, F
>        }
> }
> 
> On 2 February 2016 at 10:53, Amir Michail via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> These labels allow you to group items in an enum:
> 
> enum X {
> L1:
> case A, B
> case C
> L2:
> case D, E, F
> }
> 
> switch x {
> case L1: handleL1(x)
> case L2: handleL2(x)
> }
> 
> func handleL1(x:X) {
>   switch x L1 {
>     case .A: ...
>     case .B: ...
>     case .D: ...
>   }
> }
> 
> func handleL2(x:X) {
>   switch x L2 {
>     case .D: ...
>     case .E: ...
>     case .F: ...
>   }
> }
> _______________________________________________
> 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>
> 
> 
> 
> -- 
>   -- Howard.

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


More information about the swift-evolution mailing list