Skip to content

Instantly share code, notes, and snippets.

@donut
Created March 9, 2016 19:34
Show Gist options
  • Save donut/2ba63046c6a1daecf8ea to your computer and use it in GitHub Desktop.
Save donut/2ba63046c6a1daecf8ea to your computer and use it in GitHub Desktop.
Adds Dictionary.mapValues method
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