Created
July 30, 2020 05:06
-
-
Save WorldDownTown/507d2d614e8d0aa1d30582fe4179182e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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