<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="">The $ 'operator' would also be a good option because it matches the $0 syntax which is not far away logically.<br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;">______________________<br class=""><br class="">Benjamin Herzog</div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br class=""></div><br class="Apple-interchange-newline">
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 9. Jul 2017, at 00:00, Robert Bennett via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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=""><div class="">I’m not sure about needing a universal promotion operator in Swift. However, in the case of KeyPaths, I think a leading $ (not currently a valid operator) would work well.</div><div class=""><br class=""></div><div class="">prefix operator $</div><div class="">prefix func $&lt;T,U&gt;(rhs:&nbsp;KeyPath&lt;T,U&gt;) -&gt; (T)-&gt;U&nbsp;{&nbsp;return&nbsp;{ $0[keyPath: rhs] } }</div><div class=""><br class=""></div><div class="">guys.map($\.name)</div><div class=""><br class=""></div><div class="">This reads really well to me because the $ is suggestive of the “functionization” of the KeyPath. Also, this is guaranteed to have no compatibility issues (right?) because it’s currently forbidden.</div><div class=""><br class=""></div><div class="">(I’m only suggesting giving the leading $ this functionality, not necessarily achieving this by making it a valid operator — in fact, it would probably be best if this functionality were “hard-coded” just as it is currently hard-coded for use in $0.)</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 8, 2017, at 5:46 PM, Benjamin Herzog via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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=""><div class="">Is this operator common in other languages? I would actually expect that the conversation is not 'almost-implicit' but completely implicit instead. I think both - a prefix and postfix operator - are not obvious enough what happens here,&nbsp;especially because this kind of conversion is not happening in other parts of the language.<div class="">All conversions are implicit (from explicit type to protocol, from Swift stdlib types to Objective-C types, from any type to Any, …) currently.</div><div class=""><br class=""></div><div class=""><div class="signature">______________________<br class=""></div><div class="signature"><br class=""></div><div class="signature">Benjamin Herzog</div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div></div><div class=""><blockquote type="cite" class=""><div class="">On 8. Jul 2017, at 22:10, Hooman Mehr via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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="">I like this promote operator idea. I have been defining similar operators for specific projects almost at random. It makes sense to come up with a well-defined behavior and name for such operators, as a common practice as you suggest.<div class=""><br class=""></div><div class="">The problem with the postfix operator is that it does not currently work without an extra set of parenthesis:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">postfix<span style="" class=""> </span>operator<span style="" class=""> ^</span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">postfix</span> <span style="color: #ba2da2" class="">func</span> ^&lt;T,U&gt;(lhs: <span style="color: #703daa" class="">KeyPath</span>&lt;<span style="color: #4f8187" class="">T</span>,<span style="color: #4f8187" class="">U</span>&gt;) -&gt; (<span style="color: #4f8187" class="">T</span>)-&gt;<span style="color: #4f8187" class="">U</span> { <span style="color: #ba2da2" class="">return</span> { $0[keyPath: lhs] } }</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">struct</span> Guy { <span style="color: #ba2da2" class="">let</span> name: <span style="color: #703daa" class="">String</span> }</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> guys = [</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #4f8187" class="">Guy</span>(name: <span style="color: #d12f1b" class="">"Benjamin"</span>),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #4f8187" class="">Guy</span>(name: <span style="color: #d12f1b" class="">"Dave"</span>),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #4f8187" class="">Guy</span>(name: <span style="color: #d12f1b" class="">"Brent"</span>),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #4f8187" class="">Guy</span>(name: <span style="color: #d12f1b" class="">"Max"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">]</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #4f8187" class="">guys</span><span style="" class="">.map(\.name</span><span style="text-decoration: underline;" class="">^</span><span style="" class="">) </span>// Error: Invalid component of Swift key path</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #4f8187" class="">guys</span>.<span style="color: #3e1e81" class="">map</span>((\.name)^) <span style="color: #008400" class="">// This works</span></div></div><div class=""><span style="color: #008400" class=""><br class=""></span></div><div class="">Is this a bug?&nbsp;</div><div class=""><br class=""></div><div class="">That is the reason I used a prefix operator (~) in my suggestion in the a previous e-mail on this thread.</div></div></div></blockquote></div><br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br 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>