<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">I'm +1 for adding mapValues. Very useful functionality and trivial to implement. </div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div class="bloop_container"><div class="bloop_frame"> > > I.e. I suggest to implement and mapKeys() also. It could be also useful in some situations.<br>> `mapKeys` is much more dangerous, because you could end up mapping many values into a single key. You kind of need to combine the values somehow. Perhaps:<br>> <br>> extension Dictionary {<br>> func mapValues<outvalue>(_ valueTransform: @noescape Value throws ->OutValue) rethrows ->[Key: OutValue] { … }<br>> <br>> func mapKeys<outkey: hashable="">(_ keyTransform: @noescape Key throws ->OutKey) rethrows ->[OutKey: [Value]] { … }<br>> <br>> // Possibly flatMap variants, too?<br>> }<br>> <br>> extension Dictionary where Value: Sequence {<br>> func reduceValues<outvalue>(_ initial: OutValue, combine: @noescape (OutValue, Value.Iterator.Element) throws ->OutValue) rethrows ->[Key: OutValue] {<br>> return mapValues { $0.reduce(initial, combine: combine) }<br>> }<br>> }<br>> <br>> Which you would end up using like this:<br>> <br>> let wordFrequencies: [String: Int] = …<br>> let firstLetterFrequencies: [Character: Int] = wordFrequencies.mapKeys { $0.characters.first! }.reduceValues(0, combine: +)<br>> <br>> --<br>> Brent Royal-Gordon<br>> Architechies<br>> <br>> <br>> <br>> </outvalue></outkey:></outvalue></div></div><br><div class="bloop_sign" id="bloop_sign_1460543250984733952"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Miguel Angel Quinones<br></div></div></body></html>