Skip to content

Instantly share code, notes, and snippets.

@tangyumeng
Created January 24, 2020 05:03
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 tangyumeng/f326534883b5e1830d45e723870c817e to your computer and use it in GitHub Desktop.
Save tangyumeng/f326534883b5e1830d45e723870c817e to your computer and use it in GitHub Desktop.
Sequence unique 稳定版
extension Sequence where Element: Hashable {
func unique() -> [Element] {
var seen: Set<Element> = []
return filter { (element) -> Bool in
if (seen.contains(element)) {
return false
} else {
seen.insert(element)
return true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment