Last active
April 2, 2017 16:28
-
-
Save florianpircher/d76122568aaf483dc6d60065c72e8105 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 Self.Iterator.Element: Hashable { | |
func unique() -> [Self.Iterator.Element] { | |
var knownElements = Set<Self.Iterator.Element>() | |
return self.filter { element -> Bool in | |
if !knownElements.contains(element) { | |
knownElements.insert(element) | |
return true | |
} | |
return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment