Skip to content

Instantly share code, notes, and snippets.

@WorldDownTown
Created July 30, 2020 05:06
Show Gist options
  • Save WorldDownTown/507d2d614e8d0aa1d30582fe4179182e to your computer and use it in GitHub Desktop.
Save WorldDownTown/507d2d614e8d0aa1d30582fe4179182e to your computer and use it in GitHub Desktop.
extension Sequence where Iterator.Element: Hashable {
var unique: [Iterator.Element] {
var checked: Set<Iterator.Element> = []
return filter { checked.insert($0).inserted }
}
}
extension Sequence where Iterator.Element: Equatable {
var unique: [Iterator.Element] {
reduce([]) { $0.contains($1) ? $0 : $0 + [$1] }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment