<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=""><div>Hi, </div><div><br class=""></div><div>I think it depends on how expensive the indexed access is on the collection. I use it primarily on arrays, where self[i] essentially boils down to a pointer dereference, so I expect the generated code to be very efficient. Your version might be faster for collection with expensive element access, but it should be slower for arrays and the like, as it involves additional intermediate structure allocations and copies. </div><div><br class=""></div><div>— Taras</div><div><br class=""></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="">Just a side note that you could also:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(73, 162, 210);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">SequenceType</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> order(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">@noescape</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> isOrderedBefore: (Generator.Element, Generator.Element) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -> [</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] {</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);" class="">enumerate</span><span style="font-variant-ligatures: no-common-ligatures;" class="">().</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);" class="">sort</span><span style="font-variant-ligatures: no-common-ligatures;" class="">{ isOrderedBefore($0.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, $1.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) }.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);" class="">map</span><span style="font-variant-ligatures: no-common-ligatures;" class="">{ $0.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""></span><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(203, 203, 203);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">...</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);" class="">3</span><span style="font-variant-ligatures: no-common-ligatures;" class="">).</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);" class="">reverse</span><span style="font-variant-ligatures: no-common-ligatures;" class="">().</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);" class="">order</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(<) </span><span style="font-variant-ligatures: no-common-ligatures;" class="">// [3, 2, 1, 0]</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">This way you can `order` all sequences, and it is more efficient as you don’t fetch elements by index inside the `isOrderedBefore`. (You could also *not* `map` at the end and return all the elements along with their original indexes.)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">milos</span></div></div></div></blockquote></div><br class=""></body></html>