<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=""><blockquote type="cite" class="">On Jul 25, 2016, at 2:28 PM, Pyry Jahkola via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 25 Jul 2016, at 21:23, Nevin Brackett-Rozinsky <<a href="mailto:nevin.brackettrozinsky@gmail.com" class="">nevin.brackettrozinsky@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">My one question is, will I be able to write `someCollection.sort(.ascending)` and get the expected result? (This could be an additive future direction.)</span></div></blockquote></div><div class=""><br class=""></div><div class="">To sort to ascending order, you'd still just call `.sort()` with no arguments.</div><br class="">To limit the scope of this proposal somewhat, I moved the introduction of new sorting functions into the Future directions section. All of those changes are additive in a way or another:<div class=""><br class=""></div><div class="">1. The default .sort() function would use `<=>` instead of `<`.</div><div class=""><br class=""></div><div class="">(a) On the one hand, we'd get improved performance in cases like Array<String>.sort() where doing another `<` comparison would be more costly.</div><div class="">(b) On the other hand, we'd get well-defined behaviour when sorting Double arrays containing NaNs, because all non-NaN values would be sorted into one contiguous subrange of the result.</div></div></div></blockquote><br class=""></div><div>Two quick questions… </div><div>1) What about adding an `isInvalid` case? That way types (such as Double/Float) which have “unordered” values can check for an invalid comparison.</div><div>2) What about making `Ordering` a tuple instead of an enum? “typealias Ordering = (isLessThan: Bool, isEqual: Bool, isGreaterThan: Bool, isInvalid: Bool)”? It’d take up more space on the stack, but I think this:</div><div>func < (lhs: Int, rhs: Int) -> Bool {</div><div> return (lhs <=> rhs).isLessThan</div><div>}</div><div>or even this:</div><div><div>func < (lhs: Int, rhs: Int) -> Bool {</div><div> let ord = (lhs <=> rhs).isLessThan</div><div> return ord.isLessThan && !ord.isInvalid</div><div>}</div><div class=""><br class=""></div></div><div>would execute faster than this:</div><div><div>func < (lhs: Int, rhs: Int) -> Bool {</div><div> switch (lhs <=> rhs) {</div><div> case lessThan: return true</div><div> default: return false</div><div>}</div><div class=""><br class=""></div><div class="">because there wouldn’t be any branching beyond what’s necessary to do the actual comparison.</div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></div></body></html>