Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created December 19, 2022 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/e15f9c1243aad2484e8f80cca6e1798d to your computer and use it in GitHub Desktop.
Save laevandus/e15f9c1243aad2484e8f80cca6e1798d to your computer and use it in GitHub Desktop.
extension RangeReplaceableCollection where Element: Equatable {
@discardableResult mutating func remove(_ element: Element) -> Bool {
guard let index = self.firstIndex(of: element) else { return false }
remove(at: index)
// Remove other duplicate elements by recursivly calling it again
remove(element)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment