CollectionDuplicateRemoval is a Swift Package Manager package for iOS/tvOS (10.0 and above), watchOS (4.0 and above), and macOS (10.14 and above), under Swift 5.0 and above, adding protocol extensions to Collection
in order to define a function that returns an array of the elements of the collection, with duplicates removed.
public extension Collection where Element: Equatable {
/// O(n^2) in the worst case.
func duplicatesRemoved() -> [Element]
}
public extension Collection where Element: Equatable & Comparable {
/// O(n.log(n)) in the worst case.
func duplicatesRemoved() -> [Element]
}
public extension Collection where Element: Hashable {
/// O(n) in the worst case, if the set operations
/// contains(:) and insert(:) are O(1).
func duplicatesRemoved() -> [Element]
}
CollectionDuplicateRemoval is provided only as a Swift Package Manager package, because I'm moving away from CocoaPods and Carthage, and can be easily installed directly from Xcode.
CollectionDuplicateRemoval is available under the MIT license. See the LICENSE file for more info.