Re: [swift-users] Restricting associated values

2017-06-19 Thread Karl Wagner via swift-users
> On 19. Jun 2017, at 04:30, Nevin Brackett-Rozinsky via swift-users > wrote: > > Is there a way to restrict the associated values of an enum? For example, > suppose I have this type: > > enum Angle { > case radians(Double) > case degrees(Double) > } > > I want to ensure that the rad

Re: [swift-users] Restricting associated values

2017-06-19 Thread Karl Wagner via swift-users
> On 19. Jun 2017, at 20:03, Karl Wagner wrote: > > >> On 19. Jun 2017, at 04:30, Nevin Brackett-Rozinsky via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Is there a way to restrict the associated values of an enum? For example, >> suppose I have this type: >> >> enum Angle {

Re: [swift-users] Restricting associated values

2017-06-19 Thread Travis Griggs via swift-users
> On Jun 18, 2017, at 10:33 PM, Howard Lovatt via swift-users > wrote: > > To me Angle is a unit with two common representations: radians and degrees. > It's not an enum because it doesn't have two values, it has one value that > you can view in two ways. > > Therefore I would make an Angle

Re: [swift-users] Restricting associated values

2017-06-18 Thread Howard Lovatt via swift-users
To me Angle is a unit with two common representations: radians and degrees. It's not an enum because it doesn't have two values, it has one value that you can view in two ways. Therefore I would make an Angle struct, something like: //: Angle struct instead of angle enum import Foundation str

Re: [swift-users] Restricting associated values

2017-06-18 Thread David Sweeris via swift-users
> On Jun 18, 2017, at 19:30, Nevin Brackett-Rozinsky via swift-users > wrote: > > Is there a way to restrict the associated values of an enum? For example, > suppose I have this type: > > enum Angle { > case radians(Double) > case degrees(Double) > } > > I want to ensure that the rad

[swift-users] Restricting associated values

2017-06-18 Thread Nevin Brackett-Rozinsky via swift-users
Is there a way to restrict the associated values of an enum? For example, suppose I have this type: enum Angle { case radians(Double) case degrees(Double) } I want to ensure that the radians values is always in [0, 2π) and the degrees values is always in [0, 360). Ideally I would like to