Proposal: "if switch x case" and "for switch x case ... in"


(Amir Michail) #1

Examples:

if switch x case 1…3 { … }

for switch x case .Some(_) in args { print(x!) }


(Donnacha Oisín Kidney) #2

I think that syntax already exists:

let x = 2

if (1...3).contains(x) { print(1) }

let ar: [Int?] = [1, 2, nil, 4]

for case x? in ar {
  print(x)
}

···

On 11 Jan 2016, at 00:58, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

Examples:

if switch x case 1…3 { … }

for switch x case .Some(_) in args { print(x!) }

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Amir Michail) #3

I think that syntax already exists:

let x = 2

if (1...3).contains(x) { print(1) }

let ar: [Int?] = [1, 2, nil, 4]

for case x? in ar {
  print(x)
}

I think what I proposed might be a more intuitive replacement for the existing “if case” and “for case”.

···

On Jan 10, 2016, at 9:22 PM, Donnacha Oisín Kidney <oisin.kidney@gmail.com> wrote:

On 11 Jan 2016, at 00:58, Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Examples:

if switch x case 1…3 { … }

for switch x case .Some(_) in args { print(x!) }

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution