<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 Dec 31, 2015, at 4:14 AM, Tino Heth <<a href="mailto:2th@gmx.de" class="">2th@gmx.de</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" 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;"><font face="Menlo" class="">func byComparing<T, U: Comparable>(getComparisonKey: (T)->U) -> (T, T) -> Bool {</font></div><div class="" 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;"><font face="Menlo" class=""> return { getComparisonKey($0) < getComparisonKey($1) }</font></div><div class="" 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;"><font face="Menlo" class="">}</font></div></div></blockquote></div>I've written something similar to bring file URLs into the order of their creation dates.<div class="">It is a small extension for collection types, and its only downside will disappear as soon as properties are accessible via method calls (afair there is a proposal in the making).</div><div class=""><br class=""></div><div class="">It was quite a lot fiddling with generics, and I don't have the tiny piece of code on my own computer, but it works in a way that you can do</div><div class="">let sorted = array.sortUsingAccessor(ElementType.methodThatReturnsComparable)</div><div class="">Beside the problems with properties, I really liked that approach.</div></div></div></blockquote><div><br class=""></div>This seems to be essentially the same design as Susan’s, and has the same problem: it requires a new overload for every algorithm that takes a comparison predicate.<br class=""></div><br class=""><div class="">
-Dave
</div>
<br class=""></body></html>