[swift-evolution] ternary operator ?: suggestion

Craig Cruden ccruden at novafore.com
Mon Jan 11 00:23:19 CST 2016


I have thought about it a bit more and I think this would cover all the cases that interest me (in addition to others needs for a little more conciseness on the most simple case).  

I also think we need to be clear that the “case” (or cases) and “default” are is really just a partial function which in it’s entirety is really just a complete function for used wherever a complete function (exhaustive) can be passed (e.g. reduce, filter, etc.) - otherwise they might get confused on why we are adding it to “map”.  

The optional where clause should also be part of the case clause as part of the proposal.  

There would be no need for statement based “fallthrough”.

You mentioned your proposal….  have you drafted a formal proposal draft?



> On 2016-01-10, at 12:41:03, Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I agree that it would be really useful to keep things concise. I am going to suggest again an idea I had in the past, it is also in my proposal, which might work well for this problem. This might address the verbosity of the “case” and at the same time make it obvious we are dealing with a switch expression. So both would be valid: 
> 
> 	let num = color.map {
> 		cases   .Red: 100, 
> 			     .Green:  200, 
> 			     .Blue: 300
> 		default: -1 
> 	}
> 	let num = color.map {
> 		case     .Red: 100
> 		case     .Green:  200 
> 		case     .Blue: 300
> 		default: -1 
> 	}
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160111/81552fac/attachment.html>


More information about the swift-evolution mailing list