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

Robert Widmann devteam.codafi at gmail.com
Tue Mar 14 00:33:10 CDT 2017


This feature keeps being brought up.  SR-3050 <https://bugs.swift.org/browse/SR-3050> and rdar://problem/28952398 <rdar://problem/28952398> are tracking it, as well as this Evolution proposal by Jacob <https://github.com/apple/swift-evolution/pull/114>.  The implementation has been discussed multiple times on social media (one example that comes to mind <https://twitter.com/jtbandes/status/834633693138350080>).  At this point it’s just a matter of sitting down to flesh out the implementation and seeing its consequences on Swift code, which we now have ample time to do because this feature is not in scope for Swift 4.

~Robert Widmann

> On Mar 10, 2017, at 1:15 PM, Trevör ANNE DENISE via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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?
> 
> 
> 
> Trevör
> _______________________________________________
> 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/20170314/e61c59de/attachment.html>


More information about the swift-evolution mailing list