Created
March 9, 2016 19:34
-
-
Save donut/2ba63046c6a1daecf8ea to your computer and use it in GitHub Desktop.
Adds Dictionary.mapValues method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Dictionary { | |
func mapValues<T>(transform: Value->T) -> Dictionary<Key,T> { | |
// Adapted from http://stackoverflow.com/a/29460871/134014 | |
var dict = [Key:T]() | |
for (key, value) in zip(self.keys, self.values.map(transform)) { | |
dict[key] = value | |
} | |
return dict | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment