<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 1, 2016, at 2:28 PM, Sergey Bolshedvorsky &lt;<a href="mailto:sergey@bolshedvorsky.com" class="">sergey@bolshedvorsky.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi All,<div class=""><br class=""></div><div class="">I would like to clarify the API endpoints based on your feedback. Am I missing something?</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span>CollectionType<span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> rotatedAt(middle: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">/* -&gt; Return Type */</span> {</div></div></div></div></blockquote><div><br class=""></div>Now that I look, “rotatingFirstFrom” might be better, since it makes it very clear what middle does.&nbsp;</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// This should be handled by slicing and rotating a slice.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// let result = c.flatten(CollectionOfTwo(c[midPoint..&lt;c.endIndex], c[startIndex..&lt;midPoint] ))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// return (result, calculateIndexOfMidPoint())</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CollectionType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Index : ForwardIndexType {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> rotatedInPlace(middle: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span> {</div></div></div></div></blockquote><div><br class=""></div>These should be called “rotateFirstFrom.” &nbsp;The API guidelines are moving toward dropping the InPlace convention where possible.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// Implement ForwardIndexType algorithm</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// Return the index of the old start element</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CollectionType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Index : BidirectionalIndexType {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> rotatedInPlace(middle: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// Implement BidirectionalIndexType algorithm</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>// Return the index of the old start element</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CollectionType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Index : RandomAccessIndexType {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> rotatedInPlace(middle: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// Implement RandomAccessIndexType algorithm</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>// Return the index of the old start element</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div></div></div></blockquote><div><br class=""></div>I have heard one C++ stdlib developer argue that only two of these algorithms are needed. &nbsp;I don’t know whether to believe him, but it might be worth doing some benchmarks.</div><div>&nbsp;<br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span>LazyCollectionType<span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span>@warn_unused_result</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> rotatedAt(middle: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Index</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">/* -&gt; Return Type */</span> {</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Many of our eager algorithms for are implemented by copying lazy views to an array.</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// calculateIndexOfMidPoint can start out being O(N) if necessary; you should be able to add enough</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// API to the LazyFlattenCollection that you can synthesize the position more efficiently though.</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class="">&nbsp; &nbsp; }</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;" class="">}</div></div></div></div></blockquote><div><br class=""></div>I think maybe you want another version for bidirectional collections?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><div style="margin: 0px; line-height: normal;" class="">Sergey</div><div style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;" class=""><br class=""></div></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 29 Dec 2015, at 23:27, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 29, 2015, at 7:30 AM, Sergey Bolshedvorsky &lt;<a href="mailto:sergey@bolshedvorsky.com" class="">sergey@bolshedvorsky.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Hi Dmitri,</div><div class=""><br class=""></div><div class="">Thank you for your feedback! I’ve updated a proposal based on your comments:&nbsp;<a href="https://github.com/apple/swift-evolution/pull/77" target="_blank" class="">https://github.com/apple/swift-evolution/pull/77</a></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">What jumps at me immediately is that the APIs are using integers to specify positions in the collection.&nbsp; I think they should be using collection's indices instead.</div></div></div></div></blockquote>Yes you are right, the APIs should use collection indexes.&nbsp;</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">I'm unsure why we need `first` and `last` -- shouldn't the API operate on the whole collection?&nbsp; We have slices to operate on subsequences.</div></div></div></div></blockquote></div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">The C++ implementation allows to rotate all elements of collection or only some of them. A precondition of this function is that</div><div class="">0 &lt;= first &lt;= middle &lt;= last &lt; count</div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div>This should be handled by slicing and rotating a slice. In-place slice mutation is not yet efficient, but we have an open radar asking for the necessary core language feature to make it so (non-pointer proxy addressors).</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px;"><div dir="ltr" class=""><div class="gmail_extra">Another point to consider is how the call site of these functions looks like:</div></div></blockquote><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="font-size: 11px; font-family: Menlo;">&nbsp;I’ve added 2 API usage examples to PR:</div><div class="" style="font-size: 11px; font-family: Menlo;"><br class=""></div><div class=""><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">Example of rotating all elements of the collection:</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; min-height: 13px;"><br class=""></div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">let rotated = numbers.rotateFrom(0, middle: 3, last: 8)</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">// rotated contains&nbsp;[4, 5, 6, 7, 8, 9, 1, 2, 3]</div></div></div></div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div>There should be an in-place rotation algorithm as well, and for both varieties we should have a way of getting back the index of the old start element in the rotated collection. &nbsp;I would start with the in-place algorithms are likely more of a challenge.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class=""><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">Example of rotating some elements of the collection:</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal; min-height: 13px;"><br class=""></div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">let numbers = [10, 12, 13, 11, 15, 14]</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">let rotated = numbers.rotateFrom(1, middle: 3, last: 4)</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;">// rotated contains [10, 11, 12, 13, 15, 14]</div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;"><br class=""></div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><blockquote type="cite" class="" style="font-size: 12px; font-family: Helvetica;"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">It is interesting that you are proposing that the new algorithms should produce lazy views.&nbsp; I agree this is consistent with the rest of the library, but I'm worried about the performance implications.&nbsp; Have you thought about this?&nbsp; One point to keep in mind is that you can implement the `_copyToNativeArrayBuffer()` and `_initializeTo()` entry points in all new lazy collections, using the optimal eager algorithm.&nbsp; This way, converting them to arrays will be fast.</div></div></div></div></blockquote><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">Thanks for pointing out the performance issue with lazy views. I will draft the implementation of algorithms for regular collections at first and then I will think how it can be reused with lazy views.</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div>Err, I don’t think Dmitri pointed anything out; he merely asked you to consider performance. &nbsp;But I must admit that I don’t understand the concern. &nbsp;Many of our eager algorithms for are implemented by copying lazy views to an array.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Personally, I would implement a rotate as something like:</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">extension CollectionType {</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; func rotatedAt(midPoint: Index) -&gt; /* Return type */{</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; &nbsp; let result = c.lazy.flatten([ c[midPoint..&lt;c.endIndex], c[startIndex..&lt;midPoint] ])</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; &nbsp; // or, for optimization, c.flatten(CollectionOfTwo(c[midPoint..&lt;c.endIndex], c[startIndex..&lt;midPoint] ))&nbsp;</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; &nbsp; return (result, calculateIndexOfMidPoint())</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; }</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">} &nbsp;</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">calculateIndexOfMidPoint can start out being O(N) if necessary; you should be able to add enough API to the LazyFlattenCollection that you can synthesize the position more efficiently though.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">Sergey</div></div></div></div></div></div><div class="" style="font-size: 11px; font-family: Menlo; margin: 0px; line-height: normal;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px;"><div dir="ltr" class=""></div></blockquote></div></div></div></div></div></div></div></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 29 Dec 2015, at 06:38, Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Dec 28, 2015 at 10:29 PM, Sergey Bolshedvorsky via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&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;"><div class="" style="word-wrap: break-word;">Hi all,<div class=""><br class=""></div><div class="">I have created a PR with with a formal proposal for this feature:&nbsp;<a href="https://github.com/apple/swift-evolution/pull/77" target="_blank" class="">https://github.com/apple/swift-evolution/pull/77</a></div><div class=""><br class=""></div><div class="">What are your thoughts?</div></div></blockquote><div class=""><br class=""></div><div class="">Thank you for the proposal!</div><div class=""><br class=""></div><div class="">What jumps at me immediately is that the APIs are using integers to specify positions in the collection.&nbsp; I think they should be using collection's indices instead.</div><div class=""><br class=""></div><div class="">I'm unsure why we need `first` and `last` -- shouldn't the API operate on the whole collection?&nbsp; We have slices to operate on subsequences.</div><div class=""><br class=""></div><div class="">It is interesting that you are proposing that the new algorithms should produce lazy views.&nbsp; I agree this is consistent with the rest of the library, but I'm worried about the performance implications.&nbsp; Have you thought about this?&nbsp; One point to keep in mind is that you can implement the `_copyToNativeArrayBuffer()` and `_initializeTo()` entry points in all new lazy collections, using the optimal eager algorithm.&nbsp; This way, converting them to arrays will be fast.</div></div><div class="gmail_extra"><br class=""></div>Another point to consider is how the call site of these functions looks like:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">collection.rotate(10, middle: 20, last: 30)</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">The first number hangs in the air, it is unclear what its meaning is.</div><div class="gmail_extra"><div class=""><br class=""></div><div class="">Dmitri</div><div class=""><br class=""></div>--<span class="Apple-converted-space">&nbsp;</span><br class=""><div class="gmail_signature">main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank" class="">gribozavr@gmail.com</a>&gt;*/</div></div></div></div></blockquote></div></div></div></blockquote></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""><div class="">
-Dave

</div>
<br class=""></body></html>