[swift-evolution] Ad hoc enums / options

Félix Cloutier felixcca at yahoo.ca
Tue May 31 21:14:21 CDT 2016


I like the idea, but it is worth noting that unless the syntax is generalized (which I'm not necessarily against), the type of `operation` cannot be referenced. This means that you can't declare a variable of that type, unless you assign the argument to it.

Félix

> Le 31 mai 2016 à 09:16:56, Erica Sadun via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> Here's a function signature from some code from today:
> 
> func scaleAndCropImage(
>     image: UIImage,
>     toSize size: CGSize,
>     fitImage: Bool = true
>     ) -> UIImage {
> 
> 
> And here's what I want the function signature to actually look like:
> 
> func scaleAndCropImage(
>     image: UIImage,
>     toSize size: CGSize,
>     operation: (.Fit | .Fill) = .Fit
>     ) -> UIImage {
> 
> 
> where I don't have to establish a separate enumeration to include ad-hoc enumeration-like semantics for the call. A while back, Yong hee Lee introduced anonymous enumerations (and the possibility of anonymous option flags) but the discussion rather died.
> 
> I'm bringing it up again to see whether there is any general interest in pursuing this further as I think the second example is more readable, appropriate, and Swifty than the first, provides better semantics, and is more self documenting.
> 
> Thanks for your feedback,
> 
> -- Erica
> 
> _______________________________________________
> 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/20160531/4228226e/attachment.html>


More information about the swift-evolution mailing list