[swift-evolution] [Pitch] Add `mapValues` method to Dictionary

Haravikk swift-evolution at haravikk.me
Tue May 24 05:34:35 CDT 2016


> On 23 May 2016, at 13:03, Tim Vermeulen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I really like this idea, because indeed this wasn’t possible functionally before. I have a small remark though, wouldn’t it be better to let transform be of type (Key, Value) throws -> T instead of (Value) throws -> T? You can just ignore the key (with _) if you don’t need it, but I think it might come in handy in some cases.

For this the key/value pair constructor for Dictionary would be the better option, since the .map() method essentially already lets you do this. Adding key transformation to .mapValues() would only make it less specialised (it’s called .mapValues after all ;), plus it would be incompatible with any simultaneous/future lazy implementation since you can’t just transform the keys lazily (you also need a way to transform them back if you intend to use them for lookups).


More information about the swift-evolution mailing list