[swift-evolution] ternary operator ?: suggestion

Andrew Brown a.br at me.com
Fri Dec 11 19:14:52 CST 2015


Removing ?: is an excellent idea - but do we really need to replace it with anything new?
inline blocks seem to provide much more flexibility with the current language with no new keywords and a much clearer intent

let myColor = (
  match yourColor
  case .Blue:  .Red
  case .Green: .Blue
  case .Red:   .Blue
)

let myColor : Color = {
  switch (yourColor) {
    case .Red:   return .Green
    case .Green: return .Blue
    case .Blue:  return .Red
  }
}()


> On 7 Dec 2015, at 16:06, thorsten--- via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I would indent multiline expressions, so that the assignment target stands out.
> 
> let foo = if condition {
>            function1()
>      } else {
>            function2()
>      }
> 
> 
> Same for the switch-expression.
> 
> -Thorsten
> 
>> Am 07.12.2015 um 04:11 schrieb Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org>:
>> 
>> let foo = if condition {
>> 	function1()
>> } else {
>> 	function2()
>> }
> _______________________________________________
> 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/20151212/9aa04035/attachment.html>


More information about the swift-evolution mailing list