Skip to content

Instantly share code, notes, and snippets.

@dankogai
Last active August 29, 2015 14:02
Show Gist options
  • Save dankogai/6d79f0ca83a1d41407a8 to your computer and use it in GitHub Desktop.
Save dankogai/6d79f0ca83a1d41407a8 to your computer and use it in GitHub Desktop.
Working version of Dictionary#map in Swift
//
// 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