Algorithms.uniqued() is not ergonomic

If you do want to maintain the order of the remaining elements, here’s an in-place implementation:

extension RangeReplaceableCollection where Element: Hashable {
  mutating func removeDuplicates() {
    var alreadySeen: Set<Element> = []
    removeAll { !alreadySeen.insert($0).inserted }
  }
}
1 Like