[swift-evolution] Ad hoc enums / options

Erica Sadun erica at ericasadun.com
Tue May 31 17:00:41 CDT 2016


> On May 31, 2016, at 3:20 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> func scaleAndCropImage(
>>    image: UIImage,
>>    toSize size: CGSize,
>>    operation: (.Fit | .Fill) = .Fit
>>    ) -> UIImage {
> 
> As I said the last time this proposal came up, I think this is great right up until the moment you need `operation` to be computed or kept in a variable. Then you need to start copying your anonymous enum type all over your source, and there's no central place to make changes. The same thing is true of tuples, but tuples are easy to structure and destructure from individual values on the spot; anonymous enums aren't really like that.

And the obvious answer is you can have up to 255 of these babies for the anonymous enum type, and be able to pass numerical equivalents UInt8 with compile time substitution. That the ad-hoc enumeration is basically a syntactic shorthand for UInt8, with an enforced upper bound compile time check simplifies everything including switch statements.

-- E



More information about the swift-evolution mailing list