<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">[["hey"], ["what"]].joined().joined() // proposed<div class=""><br class=""></div><div class="">vs</div><div class=""><br class=""></div><div class="">[["hey"], ["what"]].flatten().joined(separator: “”) // now</div><div class=""><br class=""></div><div class="">I do agree that having two way of doing it now seems odd.&nbsp;</div><div class=""><br class=""></div><div class=""><div class="">[["hey"], ["what"]].joined(separator: []).joined(separator: “”) &nbsp;// now<br class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 24, 2016, at 5:47 PM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">The thing is, joined also works on arrays-of-arrays today. The only difference is that flatten doesn't have a separator.<br class=""><br class="">We wouldn't lose what your example shows — you could do this:<br class=""><br class="">[["hey"], ["what"]].joined().joined(separator: “")<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Jul 24, 2016 at 5:45 PM Jose Cheyo Jimenez &lt;<a href="mailto:cheyo@masters3d.com" class="">cheyo@masters3d.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Here is a quick example that we would loose.</div><div class=""><br class=""></div><div class="">[["hey"], ["what"]].flatten().joined(separator:&nbsp;“")</div><div class=""><br class=""></div><div class="">[["hey"], ["what"]].flatten() // &nbsp;["hey",&nbsp;"what”]</div><div class=""><br class=""></div><div class=""><div class="">The way I think of it is flatten works on array of arrays while joined works on arrays of strings.&nbsp;</div></div><div class=""><br class=""></div><div class="">I guess we could do this too</div><div class=""><br class=""></div><div class="">[["hey"], ["what"]].joined(separator: []).joined(separator:&nbsp;"")<br class=""><br class=""></div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 24, 2016, at 5:29 PM, Jose Cheyo Jimenez &lt;<a href="mailto:cheyo@masters3d.com" target="_blank" class="">cheyo@masters3d.com</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">-1 for this. To me there needs to be a difference between String (which is not a normal collection) and other regular collections.&nbsp;</div><div class=""><br class=""></div><div class="">In addition, I really don’t think this proposal has the needed strong support for the change.&nbsp;</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 22, 2016, at 3:41 PM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div dir="ltr" style="font-family:Helvetica;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Here's a proposal draft. Comments welcome:<div class=""><br class=""></div><div class=""><a href="https://gist.github.com/jtbandes/7978dc1848f7c37eeaa8e9aba27c7325" target="_blank" class="">https://gist.github.com/jtbandes/7978dc1848f7c37eeaa8e9aba27c7325</a></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Jul 22, 2016 at 2:51 PM, Ben Rimmington<span class="">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:me@benrimmington.com" target="_blank" class="">me@benrimmington.com</a>&gt;</span><span class="">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><br class="">&gt; On 22 Jul 2016, at 20:43, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank" class="">jtbandes@gmail.com</a>&gt; wrote:<br class="">&gt;<br class="">&gt;&gt; On Fri, Jul 22, 2016 at 8:35 AM, Ben Rimmington &lt;<a href="mailto:me@benrimmington.com" target="_blank" class="">me@benrimmington.com</a>&gt; wrote:<br class="">&gt;&gt;<br class="">&gt;&gt;&gt; On 22 Jul 2016, at 02:46, Jacob Bandes-Storch wrote:<br class="">&gt;&gt;&gt;<br class="">&gt;&gt;&gt; In the swift-lang Slack channel, a few of us were discussing joined(separator:) and realized that flatten() does almost exactly the same thing.<br class="">&gt;&gt;&gt;<br class="">&gt;&gt;&gt; Is there interest in renaming flatten() to joined()?&nbsp; Since joined takes a separator that's any Sequence, we can't have a default value for the separator parameter, but we can have a variant of joined() with no arguments.<br class="">&gt;&gt;<br class="">&gt;&gt; I'd like default separators for the joined() methods.<br class="">&gt;&gt;<br class="">&gt;&gt; &lt;<a href="https://bugs.swift.org/browse/SR-1428" rel="noreferrer" target="_blank" class="">https://bugs.swift.org/browse/SR-1428</a>&gt;<br class="">&gt;&gt;<br class="">&gt;&gt; But renaming flatten() to joined() seems complicated.<br class="">&gt;&gt;<br class="">&gt;&gt; &lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Flatten.swift.gyb" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/Flatten.swift.gyb</a>&gt;<br class="">&gt;&gt; &lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Join.swift" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/Join.swift</a>&gt;<br class="">&gt;<br class="">&gt; What makes it seem complicated? At the very least, one could just rename the flatten() function. There might also be an opportunity to combine the two files and delete some code from stdlib.<br class=""><br class=""></span>There's only one joined() method (for a sequence of sequences):<br class=""><br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>extension Sequence {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>func joined&lt;Separator: Sequence&gt;(separator: Separator) -&gt; JoinedSequence&lt;Self&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>}<br class=""><br class="">There are many flatten() methods (`where` clauses omitted for brevity):<br class=""><br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>extension Sequence {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>func flatten() -&gt; FlattenSequence&lt;Self&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>}<br class=""><br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>extension LazySequenceProtocol {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>func flatten() -&gt; LazySequence&lt;FlattenSequence&lt;Self.Elements&gt;&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>}<br class=""><br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>extension LazyCollectionProtocol {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>func flatten() -&gt; LazyCollection&lt;FlattenCollection&lt;Self.Elements&gt;&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>}<br class=""><br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>extension Collection {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>func flatten() -&gt; FlattenCollection&lt;Self&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>}<br class=""><br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>extension BidirectionalCollection {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>func flatten() -&gt; FlattenBidirectionalCollection&lt;Self&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="">&nbsp;</span>}<br class=""><br class="">So it's not a simple one-to-one rename.<br class=""><br class="">When there's no `separator` argument, will FlattenIterator perform better than JoinedIterator?<br class=""><span class=""><br class="">&gt;&gt; And what would happen to the flatMap() methods? Is flatten() a term of art?<br class="">&gt;&gt;<br class="">&gt;&gt; &lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/FlatMap.swift" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/FlatMap.swift</a>&gt;<br class="">&gt;<br class="">&gt; I'd say flatMap is more a "term of art" than flatten. "flatten" just describes literally what is being done. Frankly I'm surprised it was never named flattened(). Anyway, flatMap should stay.<br class=""><br class=""></span>## Future directions<br class=""><br class="">Will the flatMap(_:) methods also have flatMap(separator:_:) variants?<br class=""></blockquote><div class=""><br class=""></div><div class="">That's an interesting idea. It seems to be purely additive, however, so I imagine it wouldn't happen until after Swift 3.</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><font color="#888888" class=""><br class="">-- Ben<br class=""><br class=""></font></span></blockquote></div><br class=""></div></div><span style="font-family:Helvetica;font-size:13px;font-style: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" class="">_______________________________________________</span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:13px;font-style: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" class="">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:13px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div><br class=""></div></div></div></body></html>