<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>IMO the keys in a dictionary are not part of the contained values and therefore not part of the Functor mapping for Dictionary (obviously a map with different semantics is possible as exhibited by the standard library). &nbsp;Dictionary should implement Functor by mapping over the values while preserving the keys.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">A similar problem has been noted for Set. &nbsp;In that case it is not possible to uphold the usual Functor laws. &nbsp;IMO that points to the need for a protocol with weaker semantics than Functor. &nbsp;It would preserve the essential structure without preserving the 1 to 1 projection. &nbsp;There are likely a number of cases where this would make sense. &nbsp;Functor could inherit from that protocol adding additional semantic requirements but no additional syntactic requirements.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Matthew<br><br>Sent from my iPad</div><div><br>On Dec 16, 2015, at 8:13 AM, Al Skipp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div><blockquote type="cite" class=""><div class=""><blockquote style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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; margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><font face="monospace, monospace" class="">let myDictionary: [String:Int] = ["test": 1]</font></div><div class=""><font face="monospace, monospace" class="">var otherDictionary = myDictionary.myMap { ($0, Float($1)) }</font></div></blockquote><blockquote style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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; margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><font face="monospace, monospace" class="">// does not fail:</font></div></blockquote><blockquote style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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; margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""><font face="monospace, monospace" class="">assert(otherDictionary is [String:Float])</font></div></blockquote></div></blockquote></div><br class=""><div class="">The trouble with Dictionary is that peculiar things can happen if we can map over keys and return a Dictionary.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> dict = [<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"a"</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"b"</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"c"</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span>]</div><div style="margin: 0px;" class=""><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">let</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp;dict2 = </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">dict</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">.</span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(61, 29, 129);" class="">map</span><font face="Menlo" class=""><span style="font-size: 11px;" class=""> { (</span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(209, 47, 27);" class="">"x"</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">, $1 * </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(39, 42, 216);" class="">2</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">) } // [</span></font><font color="#d12f1b" face="Menlo" class=""><span style="font-size: 11px;" class="">“x</span></font><font face="Menlo" class=""><font color="#d12f1b" class=""><span style="font-size: 11px;" class="">”</span></font><span style="font-size: 11px;" class="">:</span><font color="#272ad8" style="font-size: 11px;" class="">6]</font></font></div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px;" class="">We start with a Dictionary with 3 keys and end up with a Dictionary with 1 key! As the order of the keys is unknown, we have no idea what the value of the key will be either, it might be 6, 4 or 2.&nbsp;</div><div style="margin: 0px;" class=""><br class=""></div><div style="margin: 0px;" class="">Swift currently avoids this bedlam by returning an Array of tuples when ‘mapping’ a Dictionary. Strictly speaking this isn’t ‘map’ in the Functor sense, but then again Dictionary is a rogue that refuses to obey the Functor laws anyway.</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAeA9rMnCwt8-2BD7aJoG30t0TCpF3dbIIYy3JwaR542uc1yLyzVVqSLir-2B0-2BymFOdZJghTExNSTFoOm2AeQ411DuFk4DUQ878Ot8xUeupQMnuHiQwzJmINnc62LukksPN4Qd4Oig5PbHfhZ-2F8trdqpKeHhBbOpVeu2Nz-2BKea4AusoPaf8H3tbaF-2FJprmNknuPr-2Bw-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;">

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>