[swift-users] [swift-evolution] for in? optionalCollection {

André “Zephyz” Videla andre.videla at gmail.com
Sat Feb 11 06:06:30 CST 2017


I don't think this use case warrants a syntax change since it can already be expressed quite elegantly with

let test: [Int]? = nil

test?.forEach { i in
    print(i)
}

Maybe "in?" could be used instead of 

let test: [Int?] = [0,1,nil,3]

for case let i? in test {
    print(i)
}
?

> On 11 Feb 2017, at 12:48, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> 
> This one started over at swift-users, with a question on how to deal with looping over containers that may be nil.
> 
> Imho the beauty of the feature is that it's simple enough to be explained in the subject line, but here is the "long" story:
> 
> let test: [Int]? = nil
> 
> // this is possible now
> if let test = test {
> 	for i in test {
> 		print(i)
> 	}
> }
> 
> // how it could be written with a modified keyword
> for i in? test {
> 	print(i)
> }
> 
> I've been thinking "in?" had been brought up long ago, but as I haven't found such a proposal, I probably confused it with the cancelled plan to write one on my own (or I just was to stupid to search ;-).
> 
> Syntactic sugar like this is definitely nothing that has priority now, but discussing it shouldn't be a big distraction — and if it turns into a proposal that as well survives review, it might be even simple enough to act as a trigger for me to finally get my hands on some real work for Swift ;-)
> 
> - Tino
> _______________________________________________
> 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-users/attachments/20170211/b108085e/attachment.html>


More information about the swift-users mailing list