[swift-evolution] ternary operator ?: suggestion
Charles Constant
charles at charlesism.com
Wed Dec 23 04:28:32 CST 2015
> In the case where your input is hashable, you could just do:
>
> let i = [.Red:0xff0000, .Green:0x00ff00, .Blue:0x0000ff][color]
You forgot to declare the type, which is mandatory if you want to use
abbreviated cases like ".Red" to construct a one-off like that. That's one
of the reasons I complained that using a Dictionary is not a pleasant
alternative earlier on. The proposal ought to infer the enum Type, just
like a normal Switch statement.
On top of that, the limitations you mention also limit usefulness.
If it weren't for these issues, it would be good enough for me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151223/fef6db1a/attachment.html>
More information about the swift-evolution
mailing list