<div dir="ltr">Great point Kevin, you&#39;ve convinced me. I&#39;m also happy with `dropWhile` for this reason. My issues with &quot;drop&quot; should be resolved in a separate proposal.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 22, 2016 at 11:17 AM, Kevin Ballard 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>




<div><div>I&#39;m rather opposed to the idea of taking the methods that take indexes and overloading them to take predicates instead. They&#39;re extremely different functionality. An index is a value that, once generated, is constant-time to use, and therefore the functions that take them are typically O(1). For example, CollectionType.suffixFrom() is documented explicitly as being O(1).<br></div>
<div> </div>
<div>But functions taking a predicate must be O(N), because they have to evaluate the predicate on every element in turn until it returns true (or false, depending on the method in question).<br></div>
<div> </div>
<div>So if we overload suffixFrom() to take a predicate, then we have one function with one overload that&#39;s always O(1), and one overload that&#39;s always O(N), and that is a great way to confuse people and hide performance issues.<br></div>
<div> </div>
<div>This is also why I&#39;m particularly fond of the takeWhile / dropWhile terminology. Besides the rather extensive precedent, the inclusion of the word &quot;while&quot; makes it clear that it&#39;s iterating over the sequence/collection, which means it&#39;s intuitively O(N).<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888">
<div> </div>
<div>-Kevin Ballard</div></font></span><div><div class="h5">
<div> </div>
<div>On Thu, Jan 21, 2016, at 02:57 PM, David Smith wrote:<br></div>
<blockquote type="cite"><div>To be honest these all seem equally &quot;weird&quot; looking to me, so my hope is that it&#39;s just a matter of familiarity 😊 My personal inclination is still that overloading suffixFrom with a predicate-taking variant is the way to go. That way it occupies the same mental slot as the existing suffixFrom method, and all you have to decide when using it is &quot;do I want to specify where to suffix from, or how to find where to suffix from?&quot;. e.g. it basically becomes sugar that turns<br></div>
<div> </div>
<div>let idx = foo.indexOf { … }<br></div>
<div>let suffix = foo.suffixFrom(idx)<br></div>
<div> </div>
<div>into<br></div>
<div> </div>
<div>let suffix = foo.suffixFrom { … }<br></div>
<div> </div>
<div><div>with the bonus feature that it works on single-pass sequences.<br></div>
<div> </div>
<div><div><span style="white-space:pre-wrap"></span>David<br></div>
<div><div><div> </div>
<div><blockquote type="cite"><div>On Jan 13, 2016, at 11:52 PM, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div> </div>
<div><div><div>&quot;suffixAfter&quot; sounds like the equivalent of dropFirst(_:), i.e. it sounds like it should take a count of elements to skip. Similarly, actually trying an expression that takes a predicate looks weird:<br></div>
<div> </div>
<div>    seq.suffixAfter({ isspace($0) })<br></div>
<div> </div>
<div>Even knowing what it&#39;s supposed to do, it&#39;s hard for me to read that expression in any sensible fashion.<br></div>
<div> </div>
<div>Also, I&#39;m not sure the &quot;noun phrase&quot; convention really makes sense for SequenceType methods. They&#39;re not technically mutating methods, but single-pass collections are in fact destructively mutated by Array-returning sequence methods (and the methods that return SubSequence also destructively mutate upon any access to the returned subsequence). Which is to say, despite not being marked as &quot;mutating&quot;, they do in fact behave like mutating methods for single-pass sequences. Which suggests that verb phrases are perfectly fine.<br></div>
<div> </div>
<div>-Kevin Ballard<br></div>
<div> </div>
<div>On Wed, Jan 13, 2016, at 08:36 PM, David Smith via swift-evolution wrote:<br></div>
<blockquote type="cite"><div> </div>
<div>Rob Rix pointed out that &quot;suffixAfter&quot; would meet all my original criteria. Not sure if keeping the original &quot;match the stuff to drop rather than the stuff to keep&quot; semantics are critical, but this gives us an option for either way 😊<br></div>
<div> </div>
<div>    David<br></div>
<div><div> </div>
<div>On Jan 13, 2016, at 6:40 PM, David Smith via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div>
</div>
<blockquote type="cite"><div><div>Naming conventions would suggest that something returning a new collection should be named with a noun phrase describing what it returns. Unfortunately, most of the ones I can think of off the top of my head are fairly clunky. &quot;suffixFromFirstNonMatchingElement&quot; describes what it does, but I haven&#39;t thought of a non-painful way to say that yet. &quot;suffixExcluding&quot; is almost right, but it incorrectly implies (to my eye at least) that the returned collection excludes all elements matching the predicate, rather than just matching prefixes. Hm, what about flipping the predicate and getting a &quot;suffixFrom&quot; overload that takes a predicate for the first matching element to be included, rather than the last matching element to be excluded?<br></div>
<div> </div>
<div><span style="white-space:pre-wrap"></span>David<br></div>
<div><div> </div>
<div><blockquote type="cite"><div>On Jan 13, 2016, at 5:54 PM, Dany St-Amant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div> </div>
<div><div style="word-wrap:break-word"><div>The dropWhile sounds weird to me, I usually would see such functionality as a dropUntil; I discard stuff until I see what I want.<br></div>
<div>Your example below doesn’t use dropWhile, but skipWhile; which sounds a bit better that dropWhile as one skip what he doesn’t want.<br></div>
<div> </div>
<div>What do the other languages use? A dropWhile, skipWhile or dropUntil concept?<br></div>
<div> </div>
<div>Dany<br></div>
<div> </div>
<div> </div>
<div><blockquote type="cite"><div>Le 11 janv. 2016 à 01:20, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :<br></div>
<div><div style="word-wrap:break-word"><div> </div>
<div>Here&#39;s a few toy examples, if it helps:<br></div>
<div> </div>
<div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">// list of all powers of 2 below some limit<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">iterate(<span style="color:rgb(39,42,216)">1</span>, apply: { $0 * <span style="color:rgb(39,42,216)">2</span> }).takeWhile({ $0 &lt; limit })<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">// first &quot;word&quot; of a string, skipping whitespace<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> cs = NSCharacterSet.whitespaceCharacterSet()<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">String(str.unicodeScalars.skipWhile({ cs.longCharacterIsMember($0.value) })<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">                         .takeWhile({ !cs.longCharacterIsMember($0.value) }))<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">// running total of an array of numbers<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">numbers.scan(<span style="color:rgb(39,42,216)">0</span>, combine: +).dropFirst()<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"> </div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">// infinite fibonacci sequence<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">iterate((<span style="color:rgb(39,42,216)">0</span>,<span style="color:rgb(39,42,216)">1</span>), apply: { ($1, $0+$1) }).lazy.map({$1})<br></div>
</div>
<div> </div>
<div>-Kevin Ballard<br></div>
<div> </div>
<blockquote type="cite"><div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On Mon, Dec 28, 2015, at 03:59 PM, Kevin Ballard wrote:<br></div>
<div>&gt;<br></div>
<div>&gt; ## Detailed design<br></div>
<div>&gt;<br></div>
<div>&gt; We add the following extension to SequenceType:<br></div>
<div>&gt;<br></div>
<div>&gt; extension SequenceType {<br></div>
<div>&gt;     func scan&lt;T&gt;(initial: T, @noescape combine: (T, Self.Generator.Element) throws -&gt; T) rethrows -&gt; [T]<br></div>
<div>&gt;     func dropWhile(@noescape dropElement: (Self.Generator.Element) throws -&gt; Bool) rethrows -&gt; [Self.Generator.Element]<br></div>
<div>&gt;     func takeWhile(@noescape takeElement: (Self.Generator.Element) throws -&gt; Bool) rethrows -&gt; [Self.Generator.Element]<br></div>
<div>&gt; }<br></div>
<div>&gt;<br></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</div>
</blockquote></div>
<div> </div>
<div><img src="https://www.fastmailusercontent.com/proxy/b56f62c953dd35e47af9e35e7e65cf5da4571de9045c2d6d82524566e169b0bf/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d316546573364777448753a4d426f45394450325d22364d2236496d22364943643d6258357e41384d223642505143763c45664368373e6931364569745f43383252653038623a78446d6a6754457a4951787c6b4a4b4739794f4b6e4570324d22324676646f47507736425b4d2232464953567a51686d2236453979796f65364d2236417f474d2236435b674333553256514361536544374a6c4d6136375c64396b625b47324c653a584f626178734342374644367b6d223244715d63593d485d41353350393f64517830753b434075313b47533762596a4864526b4334533e686a6f6b6545734054664433345277654a4b683f42316537397d4332363b44794d23344/open" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important"><br></div>
</div>
<div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
</div>
<div><img src="https://www.fastmailusercontent.com/proxy/eefeab9f47621fc0b43c8cdd386775462df532f089815082ba12e8f2b7adea88/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d316546573364777448753a4d426f45394450325d22364d2236496d22364943643d6258357e41384d223642505143763c456644603a705864577376316969385b6f634848353742455d6244375a54436762336956736274366a77717d223641447146346d4d64456577623766494d4a58464e65745e476e6f6167585c607252427b62643173456441524a7b41546a6c4967683669334b6263466a5734395a467d223244305149645055685152535b497348754d223243587f453d22364d4d2236437637354970726630383859424a5c6a48377652487436567a555537574d495360526f637472553868303842774566777533547f675949797b6260575b6d23344/open" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important"><br></div>
</div>
</blockquote><blockquote type="cite"><div><div><span>_______________________________________________</span><br></div>
<div><span>swift-evolution mailing list</span><br></div>
<div><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br></div>
<div><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div>
</div>
</blockquote><div><img src="https://www.fastmailusercontent.com/proxy/24301e8416e759fb8f0fab5459bef80dc19fa9fb7657df4a14f4b7a0f2f17783/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e44675f66733d22324d634967724848326e41554c4074695a50335473444943536d223244575b44536857644a6a7a64434a59305b494d22364238545b666734474c425265544645763454476033454540705b44343d415772707d22324d42555070386d22364570383b44593871685332796751523952665f4632623a6545697d223647754639614f43753e4163463d2236493377517f4e6166585b6a7173324c4f485161486b46763d22364f673c62755b4671523474755070565051346b6b675c433078513156705470735d6d437144477d23344d23344/open" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>
<div><img style="min-height:1px!important;width:1px!important;border-top-width:0px!important;border-right-width:0px!important;border-bottom-width:0px!important;border-left-width:0px!important;margin-top:0px!important;margin-bottom:0px!important;margin-right:0px!important;margin-left:0px!important;padding-top:0px!important;padding-bottom:0px!important;padding-right:0px!important;padding-left:0px!important" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/eeb592f2a6dd90a157b0275b85430e635e4f80db4ad7627e0e84cdd05da7282e/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d316546573364777448753a4d426f45394450325d22364d2236496d22364943643d6258357e41384d223642505143763c456646615933756449594e6873674077723772433d22324074747631514965305e497e6336726a6a46467a4d223243787b44434d22324e6762766f407a436336623875585a7766535075425855417a5674767761375555477156327148313a513c4a68577e483974396c4753447d495a4a53726a455159794443587a5752617033375d69605f6d223642305776314f674a7c6d6e426136797d4959484c435e67447a7464425a7a497c413549434971474e636948423454434345703d2232457c4c47424f48757d4938764d223241414d23344/open"><br></div>
</div>
<div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
</div>
</div>
</div>
</div>
</blockquote><div> </div>
</div></div></div>

<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>