How come Dictionary
and Dictionary.Keys
don't conform to SetAlgebra
? The constant-time lookups could implement the various method roughly as efficiently as Set
.
My use case is that I want to diff two dictionaries to update a view selectively. I want to find out which key/value pairs are new, which ones changes, and which ones go deleted. If Dictionary.Keys
conformed to SetAlgebra
, I would just do something like:
let newKeys = newDict.keys.subtracting(oldDict.keys)
let commonKeys = newDict.keys.intersecting(oldDict.keys)
let removedKeys = oldDict.keys.subtracting(newDict.keys)
I could do all this by hopping through Set
first, but it's one extra step that I suspect shouldn't have to exist.