> On 23 Mar 2016, at 11:13, Brent Royal-Gordon via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> 
> * Allow you to attach member definitions to particular cases. It would be an 
> error if they didn't all define the same members, unless there was a 
> top-level catchall.
> 
>    enum Suit: Int {
>        var isRed: Bool { return false }
> 
>        case Hearts {
>            let description: String { return "♥️" }
>            let isRed: Bool { return true }
>        }
>        case Spades {
>            let description: String { return  "♠️" }
>        }
>        case Diamonds {
>            let description: String { return  "♦️" }
>            let isRed: Bool { return true }
>        }
>        case Clubs {
>            let description: String { return  "♣️" }
>        }
> 
>        static var all = [ Hearts, Spades, Diamonds, Clubs ]
>    }

Ah, that’s interesting! This would make enum cases less like values, and more 
like their own types.

(Or maybe not — it’s still a property of the enum itself, and the definitions 
must cover all cases. But it does suggest a different way of thinking about 
what enum cases are. Maybe it would be a good thing to have enum cases be more 
like types, and have their own properties and stuff? I don’t know…)

— Radek

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to