To clear my thoughts up a bit, that wasn&#39;t an &quot;I&#39;m too lazy to Google what these functions normally do&quot; comment, but rather an &quot;I believe proposals should provide as much context as possible about what you&#39;d like to add along with the benefits of doing so&quot; comment.<br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 10, 2016 at 9:48 PM Seth Friedman &lt;<a href="mailto:sethfri@gmail.com">sethfri@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I&#39;m not familiar with any of the functions listed and would love to see more about them and their usefulness to Swift as part of the proposal.<br><br>Thanks!<br><br>Seth<br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 9, 2016 at 5:30 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Proposal PR submitted as <a href="https://github.com/apple/swift-evolution/pull/95" rel="noreferrer" target="_blank">https://github.com/apple/swift-evolution/pull/95</a><br>
<br>
-Kevin Ballard<br>
<br>
On Mon, Dec 28, 2015, at 03:59 PM, Kevin Ballard wrote:<br>
&gt; ## Introduction<br>
&gt;<br>
&gt; Add a few more functional sequence utilities to the standard library.<br>
&gt;<br>
&gt; ## Motivation<br>
&gt;<br>
&gt; We have map, filter, and reduce, but we&#39;re missing a bunch of useful utilities like scan, iterate, takeWhile, and dropWhile. Interestingly, the stdlib includes an implementation of scan in the doc comment for LazySequenceType, it just doesn&#39;t actually provide it as API.<br>
&gt;<br>
&gt; ## Proposed solution<br>
&gt;<br>
&gt; We extend SequenceType with 3 new methods scan, takeWhile, and dropWhile. We also add a single global function iterate.<br>
&gt;<br>
&gt; ## Detailed design<br>
&gt;<br>
&gt; We add the following extension to SequenceType:<br>
&gt;<br>
&gt; extension SequenceType {<br>
&gt;     func scan&lt;T&gt;(initial: T, @noescape combine: (T, Self.Generator.Element) throws -&gt; T) rethrows -&gt; [T]<br>
&gt;     func dropWhile(@noescape dropElement: (Self.Generator.Element) throws -&gt; Bool) rethrows -&gt; [Self.Generator.Element]<br>
&gt;     func takeWhile(@noescape takeElement: (Self.Generator.Element) throws -&gt; Bool) rethrows -&gt; [Self.Generator.Element]<br>
&gt; }<br>
&gt;<br>
&gt; These all take functions, so to follow convention they&#39;re @noescape and return arrays. We also provide an extension of CollectionType that overrides a couple of these methods:<br>
&gt;<br>
&gt; extension CollectionType {<br>
&gt;     func dropWhile(@noescape dropElement: (Self.Generator.Element) throws -&gt; Bool) rethrows -&gt; Self.SubSequence<br>
&gt;     func takeWhile(@noescape takeElement: (Self.Generator.Element) throws -&gt; Bool) rethrows -&gt; Self.SubSequence<br>
&gt; }<br>
&gt;<br>
&gt; We also provide lazy versions:<br>
&gt;<br>
&gt; extension LazySequenceType {<br>
&gt;     func scan&lt;T&gt;(initial: T, combine: (T, Self.Generator.Element) -&gt; T) -&gt; LazyScanSequence&lt;Self.Elements, T&gt;<br>
&gt;     func dropWhile(dropElement: (Self.Generator.Element) -&gt; Bool) -&gt; LazyDropWhileSequence&lt;Self.Elements&gt;<br>
&gt;     func takeWhile(takeElement: (Self.Generator.Element) -&gt; Bool) -&gt; LazyTakeWhileSequence&lt;Self.Elements&gt;<br>
&gt; }<br>
&gt;<br>
&gt; extension LazyCollectionType {<br>
&gt;     func dropWhile(dropElement: (Self.Generator.Element) -&gt; Bool) -&gt; LazyDropWhileCollection&lt;Self.Elements&gt;<br>
&gt;     func takeWhile(takeElement: (Self.Generator.Element) -&gt; Bool) -&gt; LazyTakeWhileCollection&lt;Self.Elements&gt;<br>
&gt; }<br>
&gt;<br>
&gt; No collection variant of scan is provided because that would require storing the last value in the index itself, which would cause problems if the combine function isn&#39;t pure.<br>
&gt;<br>
&gt; LazyDropWhileCollection would behave similarly to LazyFilterCollection in that it runs the predicate against the elements to drop when accessing startIndex; unlike LazyFilterCollection, because there&#39;s nothing else to skip after that point, the index itself can actually be Self.Elements.Index (just like a slice). LazyTakeWhileCollection also runs the predicate against the first element when accessing startIndex, but it does need a unique index type (because endIndex has to be some sentinel value, as it doesn&#39;t know where the end is until you reach that point; this index type would therefore only conform to ForwardIndexType).<br>
&gt;<br>
&gt; And finally, we provide a global function<br>
&gt;<br>
&gt; func iterate&lt;T&gt;(initial: T, _ f: T -&gt; T) -&gt; IterateSequence&lt;T&gt;<br>
&gt;<br>
&gt; This function is inherently lazy and yields an infinite list of nested applications of the function, so iterate(x, f) yields a sequence like [x, f(x), f(f(x)), ...].<br>
&gt;<br>
&gt; -Kevin Ballard<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></blockquote></div>