Last active
August 29, 2015 14:02
-
-
Save dankogai/6d79f0ca83a1d41407a8 to your computer and use it in GitHub Desktop.
Working version of Dictionary#map in Swift
This file contains hidden or 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
// | |
// cf. http://nomothetis.svbtle.com/smashing-swift | |
// | |
extension Dictionary { | |
func map<R>(transform:(ValueType)->R)->Dictionary<KeyType, R> { | |
var result:Dictionary<KeyType, R> = [:] | |
for (k, v) in self { | |
result[k] = transform(v) | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment