[swift-evolution] Fwd: ternary operator ?: suggestion

John Randolph jcr at icloud.com
Thu Jan 7 01:36:42 CST 2016




> On Jan 6, 2016, at 11:23 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Something akin to:
> 
> let x = someValue ? 
>  case <pattern1>: result1
>  case <pattern2>: result2
>  case <pattern3>: result3
>  default: result4

This kind of feels like “switch with a return value”, which might be a useful new construct, but I would advocate that if implemented, it gets a new keyword.  Maybe like…

	let x = pick(someValue){
	  	case <pattern1>: result1
	 	case <pattern2>: result2
	 	case <pattern3>: result3
		default: result4
		}

but in practice, I’d be hard pressed to choose between this or something like making an array or dictionary of closures.

-jcr



More information about the swift-evolution mailing list