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

Howard Lovatt howard.lovatt at gmail.com
Mon Feb 1 18:05:26 CST 2016


Oops cut and past error!

enum X {

    case L1(l1: L1Type)

    case L2(l2: L2Type)

    enum L1Type {

        case A, B, C

    }

    enum L2Type {

        case D, E, F

    }

}

On 2 February 2016 at 11:03, Howard Lovatt <howard.lovatt at gmail.com> wrote:

> Isn't that just a nested enum:
>
>     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> 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
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
>
>
> --
>   -- Howard.
>



-- 
  -- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160202/53c324bb/attachment.html>


More information about the swift-evolution mailing list