<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 would really like to see something like the following added to the standard library:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>Dictionary<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> mapValues&lt;U&gt;(transform:(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Value</span>)-&gt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">U</span>)-&gt;[<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">U</span>] {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> output:[<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>:<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">U</span>] = [:]</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> (k,v) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output[k] = transform(k,v)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> output</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">It comes up enough that I have had to add it to pretty much every one of my projects. &nbsp;I also don’t feel comfortable adding it to my frameworks, since I figure a lot of people are also adding something like this to their projects, and I don’t want to cause a conflict with their version. &nbsp;Prime candidate for the standard library.</div><div class=""><br class=""></div><div class="">I like calling it ‘mapValues' as opposed to providing an override for map, since it makes the specific behavior more clear. &nbsp;I would expect ‘map' to possibly map the keys as well (though there are issues where the new keys overlap). &nbsp;I suppose you could just have a bunch of overrides for map if the compiler becomes good enough at differentiating return types: (Value)-&gt;(Value), (Key,Value)-&gt;Value, (Key, Value)-&gt;(Key,Value)</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div></body></html>