> I have a question for you. How do you think we could use this pattern in the
> generalised situation:
In general ;-) I like things that can be used universally much more than a huge
number of special cases.
But here, I'm not sure if it's not an increase of complexity:
I often if statements w
Most alternatives already where discussed in swift-user:
> Imho the "forEach" solution is flawed, because you can't break the loop, and
> the "?? []" isn't perfect either:
> I hope the compiler can optimise so that the assembly is as fast as the "if
> let" solution, but even if this is the case,
let test: [Int]? = nil
for b in test ?? [] where b != 42 {
Print(b)
}
I don't think you need new syntax since what you want can be accomplished
quite succinctly already
On Sat, Feb 11, 2017 at 8:18 AM Anton Zhilin via swift-evolution <
swift-evolution@swift.org> wrote:
for i in test ?? [] {
for i in test ?? [] {
print(i)
}
For a more general solution, we could add Optional.flatten() to support
optional sequences:
for i in test.flatten() {
print(i)
}
___
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.o
Ah I see you point a bit better.
But I don't agree with your example, since it can be easily expressed with
test?.prefix(while: { $0 != 42}).forEach { i in
print(i)
}
But arguing about examples is besides the point, I would like to stop here.
I have a question for you. How do you think we c
> 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)
> }
> What about just use
>
> test?.forEach { print($0) }
This works for the simple example, but it isn't as power
What about just use
test?.forEach { print($0) }
Zhaoxin
On Sat, Feb 11, 2017 at 7:48 PM, Tino Heth via swift-evolution <
swift-evolution@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 o
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 2
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