Created
January 24, 2020 05:03
-
-
Save tangyumeng/f326534883b5e1830d45e723870c817e to your computer and use it in GitHub Desktop.
Sequence unique 稳定版
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 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