<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Oops, you're right on the skipWhile(), that snuck in there because I was looking at the Rust documentation (and Rust uses the name skipWhile()).<br></div>
<div> </div>
<div>As for dropUntil, all of the precedent I know of behaves like a dropWhile, not a dropUntil. And dropUntil sounds weird to me; every time I've wanted to use this functionality, I do in fact want to drop the stuff I don't want, rather than dropping until some predicate becomes true.<br></div>
<div> </div>
<div>Language precedent:<br></div>
<div> </div>
<div>Rust: skip_while() and take_while()<br></div>
<div>Ruby: drop_while() and take_while()<br></div>
<div>Python: dropwhile() and takewhile()<br></div>
<div>Haskell: dropWhile and takeWhile</div>
<div> </div>
<div>-Kevin Ballard</div>
<div> </div>
<div>On Wed, Jan 13, 2016, at 05:54 PM, Dany St-Amant wrote:<br></div>
<blockquote type="cite"><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 <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> a écrit :<br></div>
<div><div style="word-wrap:break-word;-webkit-line-break:after-white-space;"><div> </div>
<div>Here'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 class="colour" style="color:rgb(39, 42, 216)">1</span>, apply: { $0 * <span class="colour" style="color:rgb(39, 42, 216)">2</span> }).takeWhile({ $0 < 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 "word" 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 class="colour" 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 class="colour" 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 class="colour" style="color:rgb(39, 42, 216)">0</span>,<span class="colour" 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>><br></div>
<div>> ## Detailed design<br></div>
<div>><br></div>
<div>> We add the following extension to SequenceType:<br></div>
<div>><br></div>
<div>> extension SequenceType {<br></div>
<div>> func scan<T>(initial: T, @noescape combine: (T, Self.Generator.Element) throws -> T) rethrows -> [T]<br></div>
<div>> func dropWhile(@noescape dropElement: (Self.Generator.Element) throws -> Bool) rethrows -> [Self.Generator.Element]<br></div>
<div>> func takeWhile(@noescape takeElement: (Self.Generator.Element) throws -> Bool) rethrows -> [Self.Generator.Element]<br></div>
<div>> }<br></div>
<div>><br></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</div>
</blockquote></div>
</blockquote><div> </div>
</body>
</html>