<div dir="ltr">A weak -1.<div><br></div><div>I&#39;m not certain that my argument holds up very well; I&#39;m just pointing out how I see this as consistent with the rest of the language. My point is that &quot;where&quot; is a keyword which adds an extra condition onto a braced block; it doesn&#39;t play a role in producing values.</div><div><br></div><div>&quot;for x in y where x &gt; 2&quot; means:</div><div><br></div><div>    var g = y.generate()</div><div>    while let x = g.next() {</div><div>        if x &gt; 2 { // added by &quot;where&quot; clause</div><div>            // contents of for-in loop here</div><div>        }</div><div>    }</div><div><br></div><div>Similarly, &quot;if let x = y where y &gt; 2&quot; means roughly:</div><div><br></div><div>    if y != nil {</div><div>        let x = y!</div><div>        if x &gt; 2 { // added by &quot;where&quot; clause</div><div>            // contents of if-statement here</div><div>        }</div><div>    }<br><div class="gmail_extra"><br></div><div class="gmail_extra">The purpose of &quot;where&quot; is merely to add an extra &quot;if&quot; without requiring another level of nesting. A plain for-in loop doesn&#39;t produce a new array of values, so using &quot;in&quot; and/or &quot;where&quot; by themselves to produce a new array isn&#39;t possible.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob Bandes-Storch<br></div></div></div></div>
<br><div class="gmail_quote">On Sat, Dec 19, 2015 at 10:10 PM, Charles Constant <span dir="ltr">&lt;<a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jacob,<div><br></div><div>I take it that&#39;s a -1 ?</div><div><br></div><div>I don&#39;t quite understand your example, because y in a &quot;for&quot; loop is an Array. So if I modify your example (I&#39;ll rename &quot;y&quot; to &quot;numbers&quot;)...</div><div> </div><div>    for x in numbers where x &gt; 2 { }<br></div><div><br></div><div><span style="font-size:13px">...my intuition immediately barks &quot;it&#39;s a filter!&quot;</span></div><div><span style="font-size:13px"><br></span></div><div>    let valid_numbers = x in numbers where x &gt; 2<br></div><div><br></div><div>I realize it&#39;s good to have a closure-based solution for map/filter/reduce, so fair enough that we let the filter method exist. Maybe if I understood Swift better (is this related to sequences?) this would all make sense... but with what grasp of Swift I do have, it makes the language feel baroque to have this &quot;where&quot; clause that looks like it ought to instantiate an array, but can&#39;t. </div><div><br></div><div><br></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 19, 2015 at 9:45 PM, Jacob Bandes-Storch <span dir="ltr">&lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It doesn&#39;t bother me, because I read it as an additional constraint on the `for` loop rather than an operation being done on the enumerated sequence. That is,<div><br></div><div>    for x in y where x &gt; 2 { }</div><div><br></div><div>is fairly consistent with </div><div><br></div><div>    if let x = y where x &gt; 2 { }</div><div><br></div><div>And you wouldn&#39;t expect to be able to do &quot;let x = y where x &gt; 2&quot;.</div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr"><div>Jacob Bandes-Storch<br></div></div></div></div>
<br><div class="gmail_quote"><div><div>On Sat, Dec 19, 2015 at 8:22 PM, Charles Constant via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Thanks Charles ,<div><br></div><div>I know it&#39;s possible to do the same thing with filter. The syntax I drew attention to would be an alternate way. </div><div><br></div><div>My only rationale is that, if it works in one place, it ought to work everywhere. The redundancy bothers me too, but since the concept exists, we may as well allow it everywhere. Otherwise, it&#39;s still redundant in a &quot;for&quot; loop (maybe performance is better, but that could be optimized?), but also inconsistent because it seems intuitively like it ought to create a subset whereas in reality it is illegal.</div><div><br></div><div>Does it bother anyone else, or am I nitpicking?</div></div></div></div><div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 19, 2015 at 7:52 PM, Charles Srstka <span dir="ltr">&lt;<a href="mailto:cocoadev@charlessoft.com" target="_blank">cocoadev@charlessoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><blockquote type="cite">On Dec 19, 2015, at 9:43 PM, Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></blockquote><div><blockquote type="cite"><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I noticed several weeks ago that the following is illegal:<br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">    let new_arr = el in arr where<span> </span></span><a href="http://el.is/" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">el.is</a><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_foo // illegal</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I assumed it would work because it&#39;s consistent with the filtering that exists in a &quot;for&quot; loop, i.e.:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">    for el in arr where<span> </span><a href="http://el.is/" target="_blank">el.is</a>_foo // legal<br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Is this &quot;new proposal&quot; material? I thought I would check in case it&#39;s already on the roadmap, or inherently wrong.</div></div></blockquote></div><br></div></div><div>I believe what you want is already possible via the “filter” method.</div><span><font color="#888888"><div><br></div><div>Charles</div><div><br></div></font></span></div></blockquote></div><br></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=P-2BsYbBZHRBuLDBJaL4DIKDNfkkjpROowTyRAObV11qzRaqAqbqp979hECJXGD8pFlX7-2F-2B-2FT-2FSlL-2F5StUcFiVW7HkjK1QDKMmQJiSJzzlaiNPIv4-2F6x13G0c5mGIZX2vZwi9R5RwLYtEe5Y-2FRhRTVadZARgWuBd8hYksyur6TdExBuEUDGCqvrte5a-2B4RtDleg4dOIkfnpvTqwMEgftmfM1mTNFITw-2Ful6vdxVxFYrPk-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></div><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></blockquote></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>