[swift-evolution] List all values of a simple enum and extension constraint to enum types

Trevör ANNE DENISE trevor.annedenise at icloud.com
Fri Mar 10 12:15:19 CST 2017

Hello everyone,

As I was writing a program, I realised that I could make it safer by being able to list all possible cases of a Swift enum.
This is similar to what has been described there:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001233.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001233.html>

Is there any updates about it since 2015?

Also, do you think this would be a good idea to make extensions constrainable by enum types, like that?
extension Type where P1: enum {

You could then write something similar to this:

protocol A {
associatedtype P1
associatedtype P2
static var p1PossibleValues:[P1] { get }
static var p2PossibleValues:[P2] { get }

extension A where P1: enum, P2: enum {
	static var p1PossibleValues:[P1] { return p1PossibleValues.allValues }
	static var p2PossibleValues:[P2] { return p2PossibleValues.allValues }

Would it make sense to do it this way?

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

More information about the swift-evolution mailing list