Replace ranges on OrderedDictionary

Why is OrderedDictionary only a Partial RangeReplaceableCollection? I'm looking to swap out my current Array<(IDType, ValueType)> for an OrderedDictionary<IDType, ValueType>, but rely on replaceSubrange, which is not implemented for OrderedDictionary. Wouldn't this method work with a dictionary literal as the newValues replacement argument?

The RandomAccessCollection API as well as a subset of the RangeReplaceableCollection API can be found under the elements computed property, to avoid confusion between element access by key and by index.

However, the uniqueness of keys isn't guaranteed in dictionary literals[1], and in case of replaceSubrange, it would not be enough for the literal to have unique keys; it should neither contain any of the keys existing outside the subrange being replaced.


  1. Indeed the default dictionary literal type KeyValuePairs explicitly allows duplicate keys. ↩︎

Bottom line remains that there is no replaceSubrange equivalent. I think there should be one.

OrderedDictionary needs to ensure that its keys are unique, and this requirement is incompatible with arbitrary insertions and replacements.