<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><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></body></html>