Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-12 Thread Mateusz Malczak via swift-evolution
t there with the ‘case’ instead of >>>> hidden in a tree of multiple ‘var’s. >>>> While I was sceptical about this proposal, Braeden’s example makes it a +1. >>>> >>>> Rien. >>>> >>>> Btw: I made the almost identical suggestion you d

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-12 Thread Mateusz Malczak via swift-evolution
ht: Int } >>> >>> var size : Size { >>> switch self { >>> case .small: return Size(width: 30, height: 30) >>> // … etc >>> } >>> } >>> } >>> >>> There is no need for these sizes to be stored

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-12 Thread Mateusz Malczak via swift-evolution
I agree, we dont event have to add a new language syntax to get this feature. Using structs as rawTypes would do the trick but 1. it should be possible to use struct initializer to define enum cases struct MyStruct { var width: Int var height: Int init(width: Int, height: Int) { ... } } enum

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-12 Thread Mateusz Malczak via swift-evolution
g extra besides the code that Braeden suggested? > > Rien. > >> On 12 Oct 2016, at 00:13, Mateusz Malczak via swift-evolution >> <swift-evolution@swift.org> wrote: >> >> That's exactly what this proposal is about. I would like to >> keep all enum properties

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-11 Thread Mateusz Malczak via swift-evolution
t; > I think we were also (separately) proposing to extend `rawValue` to take all > kinds of statically known values, like structs or tuples. Doing that would > accomplish much of the same thing. > > Someone fact-check me here! I really do think something like this would be > a goo

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-11 Thread Mateusz Malczak via swift-evolution
Hi, I think we are here discussing two different aspects of introducing this new feature - code syntax and underlying implementation. In terms of code syntax I would go with first proposal as it seems to me the simplest approach. When it comes to underlying implementation, I can imagine that

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
I just did a quick summary of this discussion and get all ideas and code examples in one place - https://github.com/malczak/enums-with-stored-properties I will try to keep that document updated, but feel free to edit it as well -- | Mateusz Malczak 2016-10-10 21:18 GMT+02:00 Haravikk

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
> I know, but what I'm saying is that this problem could be solved in the > multiple values case by allowing tuples as raw values for enums, since that > would allow you to specify both width and height. So it'd look something > like this: We have three different possible solution 1. stored

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
For simple structs this is already possible (see this example: https://swiftlang.ng.bluemix.net/#/repl/57fb8e3e4f9bcf25fdd415cd). If we focus on more complex cases where properties of Any? type are allowed I think this approach could do the trick... but still I would like to be able to access

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
> How about to a two type enums? By that I mean something like this: > > enum Enum : RawType, StoreType { > case a = (rawInstance1, storeInstance1) > case b = (rawInstance2, storeInstance2) > case c = rawInstance3, storeInstance3 // or not tuple like? > } > > let instance = Enum.a >

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
n each case. This can be called a third enumeration type >> feature, right next to associated values and rawType. >> >> -- >> | Mateusz Malczak >> >> >> 2016-10-10 13:40 GMT+02:00 Jay Abbott <j...@abbott.me.uk>: >> > Thanks for th

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
10-10 15:31 GMT+02:00 Haravikk <swift-evolut...@haravikk.me>: > > On 10 Oct 2016, at 13:04, Mateusz Malczak via swift-evolution > <swift-evolution@swift.org> wrote: > > I think, I have used quite unfortunate naming, which is a root of an > misunderstanding here. By saying

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
Jay Abbott <j...@abbott.me.uk>: >> > Thanks for the explanation Mateusz, I think I understand. So the enum >> > still >> > only has 3 cases, SMALL, MEDIUM, and LARGE, but an instance also has >> > some >> > properties? >> > >> > So some code to

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
gt; only has 3 cases, SMALL, MEDIUM, and LARGE, but an instance also has some > properties? > > So some code to use it might be: > var aFormat = Format.LARGE > aFormat.width = 150 // aFormat is still Format.LARGE - this doesn't change > > Is that right? > > On Mon, 10 Oct

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
Hi, > Perhaps it is a bit ugly, but I don’t know if allowing stored properties on > enums is the solution: that looks very ugly to me too. That may look ugly, but can be very useful, if only you think rawValue's are useful then you should also agree that stored properties would be useful :) -- |

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
Java’s constants are convenient > but they are an oddly structural feature in a particularly nominal language > which makes it not scale particularly cleanly. > > ~Robert Widmann > > On Oct 8, 2016, at 6:50 PM, Mateusz Malczak via swift-evolution > <swift-evolution@swift.org&

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-10 Thread Mateusz Malczak via swift-evolution
nt { >> switch self.unFormat { >> case let .SMALL(_, h): >> return h >> case let .MEDIUM(_, h): >> return h >> case let .LARGE(_, h): >> return h >> } >> } >> } >> >> Yeah, you’re still subject the swi

Re: [swift-evolution] [Proposal] Enums with stored properties

2016-10-08 Thread Mateusz Malczak via swift-evolution
I agree, you can achieve similar result using structs (as shown in my example 2). But it feels more natural to define it using an enumeration type. Enumeration defines a type with well defined set of possible values. Sometimes where are additional informations liked with enumeration cases (like in

[swift-evolution] [Proposal] Enums with stored properties

2016-10-08 Thread Mateusz Malczak via swift-evolution
Hi all, I would like to know you opinion on one feature I feel would be a real 'nice to have' extension to currently available enumeration type. Which is an enumeration type with stored properties. It is sometimes useful to store some extra informations along with enumeration cases. Idea here is