<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 class="">I don’t get the resistance to Dave’s solution? I think it works well and much more applicable. Taking Susan’s original example, it’s not uncommon to want to sort or filter by multiple mechanisms.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">func</span> byComparing<T, U: <span style="color: rgb(112, 61, 170);" class="">Comparable</span>>(getComparisonKey: (<span style="color: rgb(112, 61, 170);" class="">T</span>)-><span style="color: rgb(112, 61, 170);" class="">U</span>) -> (<span style="color: rgb(112, 61, 170);" class="">T</span>, <span style="color: rgb(112, 61, 170);" class="">T</span>) -> <span style="color: rgb(112, 61, 170);" class="">Bool</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> { getComparisonKey($0) <span style="color: rgb(61, 29, 129);" class=""><</span> getComparisonKey($1) }</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;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class=""><br class=""></span></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="">struct</span> Person {</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> name: <span style="color: rgb(112, 61, 170);" class="">String</span></p><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="">var</span> age: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> height: <span style="color: rgb(112, 61, 170);" class="">Int</span></p><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="">let</span> peoples = [</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>(name: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Hawk"</span>, age: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">24</span>, height: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">60</span>),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Person</span>(name: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Andrew"</span>, age: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">23</span>, height: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">66</span>)</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="color: rgb(187, 44, 162);" class="">let</span> youngest = <span style="color: rgb(79, 129, 135);" class="">peoples</span>.<span style="color: rgb(61, 29, 129);" class="">minElement</span>(<span style="color: rgb(49, 89, 93);" class="">byComparing</span> { $0.<span style="color: rgb(79, 129, 135);" class="">age</span> })</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="">let</span> tallest = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">peoples</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">maxElement</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">byComparing</span> { $0.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">height</span> })</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; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span>"youngest: <span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">youngest</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">?.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">name</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ?? </span>"<none>")"<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span>"tallest: <span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">\</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">tallest</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">?.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">name</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ?? </span>"<none>")"<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">-David</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 8:19 AM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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=""><br class=""><div class=""><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 class=""><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="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43pXkLx-2B36P-2BPNJufHeY0dgdYwl8MGfK4CypkSW5OMYLQpZ8JAzACLmS1X2AP3VNNWiu3-2FucNiitl6FBP4smTDM6L-2F2iJuf9xmgH-2FAulGBCRlE1evEHSKnvvtHvr1Go60SSWQg6twJA9h-2FI1azYRloiAZabvpjXi8osHhjfcbSVrfXcD-2B2f84baQ2LtIC2eKov79MlmX2g6dtqb5V8T18SP0-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>