https://twitter.com/narfdotpl/status/558348210079809536
extension Dictionary {
func map<A: Hashable, B>(f: (Hmm.Key, Hmm.Value) -> (A, B)) -> [A: B] {
var d: [A: B] = [:]
for (k, v) in map(self, f) {
d[k] = v
}
return d
}
}
- I thought
Hashable
is needed. Turns out it's not. - I didn't know how to reference original key and value types. Turns out
they're just
Key
andValue
. - I didn't see recursion in
map(self, f)
. :p
extension Dictionary {
func map<A, B>(f: (Element) -> (A, B)) -> [A: B] {
var d: [A: B] = [:]
for (k, v) in Swift.map(self, f) {
d[k] = v
}
return d
}
}