<div style="white-space:pre-wrap">filter() is and prefix(while:) will be available on all sequences. The for...in loop only traverses through sequences.<br><br>The meaning of the proposed while is not at all a pair for where, since where clauses in while loops would do the same thing as while clauses in for loops. That's crazy.<br></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 7, 2016 at 06:20 Vladimir.S via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My +1 to the proposal and for Charlie's opinion. I believe `while` in `for`<br>
loop would be very handy and helpful in some situations, it is a pair for<br>
existed `where`, its meaning is obvious, and its existence can't depend on<br>
existence of any method in collections. I'd like to see a formal proposal<br>
for this feature.<br>
<br>
On 07.06.2016 8:18, Charlie Monroe via swift-evolution wrote:<br>
> I strongly disagree.<br>
><br>
> Exchanging<br>
><br>
> for result in results where result.value != .Warning while result.value !=<br>
> .Error {<br>
> /// ...<br>
> }<br>
><br>
> for either<br>
><br>
> for result in results.filter({ $0.value != .Warning }).prefix(while: {<br>
> $0.value != .Error })) {<br>
> /// ...<br>
> }<br>
><br>
> or<br>
><br>
> for result in results {<br>
> if result.value == .Warning { continue }<br>
> if result.value == .Error { break }<br>
><br>
> /// ...<br>
> }<br>
><br>
> Seems like an absolute step back. Not to mention filter(_:) doesn't return<br>
> a lazy collection, but will recreate it, while the `where` will do<br>
> on-the-fly check.<br>
><br>
>> On Jun 7, 2016, at 1:34 AM, Xiaodi Wu via swift-evolution<br>
>> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>> wrote:<br>
>><br>
>> Personally, given this discussion and the one about `where` in if and<br>
>> while statements, I would not be opposed to elimination of `where` in<br>
>> control statements altogether.<br>
>><br>
>> My reasoning would be that words like filter and prefix unambiguously<br>
>> indicate what happens to elements of a sequence for which the predicate<br>
>> returns false, whereas words like where and while are ambiguous.<br>
>><br>
>> On Mon, Jun 6, 2016 at 17:52 Tim Vermeulen <<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a><br>
>> <mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>>> wrote:<br>
>><br>
>> I didn’t mean we should really get rid of the `where` clause, it’s<br>
>> great. I guess the point I was trying to make is that we can use a<br>
>> `where` clause with a `for` loop in Swift, despite the existence of<br>
>> the `filter` method. So despite `prefix(while:)` in Swift 3, there<br>
>> might be room for a `while` clause. I think it makes the code a lot<br>
>> more readable, much like how `where` can make a `for` loop a lot more<br>
>> readable than using `filter`.<br>
>><br>
>> > The burden of proof for adding new features is different from that<br>
>> for taking away existing features.<br>
>> ><br>
>> > If a feature doesn't yet exist, a successful proposal will show how<br>
>> it provides additional and non-trivial utility. If a feature already<br>
>> exists, a successful proposal to remove it will show how it is<br>
>> harmful to the language or contrary to the direction in which it is<br>
>> evolving.<br>
>> ><br>
>> > On Mon, Jun 6, 2016 at 15:38 Tim Vermeulen<<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a><br>
>> <mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>>(mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a><br>
>> <mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>>)>wrote:<br>
>> > > The functionality of the `where` clause in `for` loops also<br>
>> already can be mimicked using `filter`. Wouldn’t we have to get ride<br>
>> of the `where` clause by that logic?<br>
>> > ><br>
>> > > >The functionality being asked for here is already accepted for<br>
>> inclusion to Swift as a method on Sequence named `prefix(while:)`<br>
>> (SE-0045):<br>
>> > > ><br>
>> > > >`for element in array.prefix(while: { someCondition($0) }) { ... }`<br>
>> > > >On Mon, Jun 6, 2016 at 14:31 T.J. Usiyan via<br>
>> swift-evolution<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)>wrote:<br>
>> > > >>(As I said, I can live with `while`. I am simply presenting a<br>
>> potential point of confusion.)<br>
>> > > >>You aren't evaluating the statements in the loop 'while' the<br>
>> condition isn't met. The first time that the condition isn't met,<br>
>> evaluation of the loop stops. I get that this is technically true for<br>
>> the `while` construct but I suggest that the only reason that it<br>
>> works there is that 'stopping the first time that the condition isn't<br>
>> met' *is* the construct. Here, we have a loop that we execute for<br>
>> each thing and we're tacking on/intermingling the `while` construct.<br>
>> > > >><br>
>> > > >><br>
>> > > >><br>
>> > > >>On Mon, Jun 6, 2016 at 2:19 PM, Thorsten<br>
>> Seitz<<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a><br>
>> <mailto:<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>>(mailto:<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a><br>
>> <mailto:<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>>)(mailto:<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a><br>
>> <mailto:<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>>)>wrote:<br>
>> > > >>><br>
>> > > >>>>Am 06.06.2016 um 19:43 schrieb Tim Vermeulen via<br>
>> swift-evolution<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)>:<br>
>> > > >>>><br>
>> > > >>>>I also considered `until`, but it would be a bit confusing<br>
>> that `where` makes sure a condition is met, while `until` makes sure<br>
>> the condition isn’t met. I think `while` makes more sense because it<br>
>> corresponds to `break` in the same way that `where` corresponds to<br>
>> `continue`.<br>
>> > > >>><br>
>> > > >>>That's a good argument! The only drawback is that `while` and<br>
>> `where` look quite similar at a glance.<br>
>> > > >>><br>
>> > > >>>-Thorsten<br>
>> > > >>><br>
>> > > >>>><br>
>> > > >>>>>`while`, to me, actually reads like it should do what<br>
>> `where` does.<br>
>> > > >>>><br>
>> > > >>>>To me, `while` reads like it should stop the loop once the<br>
>> condition isn’t met, just like in a while loop.<br>
>> > > >>>><br>
>> > > >>>>>I hadn't thought about `while` in this regard but wouldn't<br>
>> `until` make more sense? `while`, to me, actually reads like it<br>
>> should do what `where` does. In any case, whether it is `while` or<br>
>> `where`, this seems like a reasonable feature in my opinion.<br>
>> > > >>>>><br>
>> > > >>>>>TJ<br>
>> > > >>>>><br>
>> > > >>>>>On Mon, Jun 6, 2016 at 5:15 AM, Tim Vermeulen via<br>
>> swift-evolution<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)>wrote:<br>
>> > > >>>>>>We can already use a where clause in a for loop like this:<br>
>> > > >>>>>><br>
>> > > >>>>>>for element in array where someCondition(element) {<br>
>> > > >>>>>>// …<br>
>> > > >>>>>>}<br>
>> > > >>>>>><br>
>> > > >>>>>>which basically acts like<br>
>> > > >>>>>><br>
>> > > >>>>>>for element in array {<br>
>> > > >>>>>>guard someCondition(element) else { continue }<br>
>> > > >>>>>>// …<br>
>> > > >>>>>>}<br>
>> > > >>>>>><br>
>> > > >>>>>>Sometimes you want to break out of the loop when the<br>
>> condition isn’t met instead. I propose a while clause:<br>
>> > > >>>>>><br>
>> > > >>>>>>for element in array while someCondition(element) {<br>
>> > > >>>>>>// …<br>
>> > > >>>>>>}<br>
>> > > >>>>>><br>
>> > > >>>>>>which would be syntactic sugar for<br>
>> > > >>>>>><br>
>> > > >>>>>>for element in array {<br>
>> > > >>>>>>guard someCondition(element) else { break }<br>
>> > > >>>>>>…<br>
>> > > >>>>>>}<br>
>> > > >>>>>><br>
>> > > >>>>>>I can see this particularly being useful if we have a<br>
>> sorted array and we already know that once the condition isn’t met,<br>
>> it won’t be met either for subsequent elements. Another use case<br>
>> could be an infinite sequence that we want to cut off somewhere<br>
>> (which is simply not possible using a where clause).<br>
>> > > >>>>>>_______________________________________________<br>
>> > > >>>>>>swift-evolution mailing list<br>
>> > > >>>>>><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)<br>
>> > > >>>>>><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>> > > >>>>_______________________________________________<br>
>> > > >>>>swift-evolution mailing list<br>
>> > > >>>><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)<br>
>> > > >>>><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>> > > >><br>
>> > > >>_______________________________________________<br>
>> > > >>swift-evolution mailing list<br>
>> > > >><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>)<br>
>> > > >><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>> > > ><br>
>> > > ><br>
>> > > >_______________________________________________<br>
>> > swift-evolution mailing list<br>
>> > <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br>
>> > <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
>> ><br>
>> ><br>
>> ><br>
>><br>
>> _______________________________________________<br>
>> swift-evolution mailing list<br>
>> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br>
>> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>