Skip to content

Instantly share code, notes, and snippets.

@florianpircher
Last active April 2, 2017 16:28
Show Gist options
  • Save florianpircher/d76122568aaf483dc6d60065c72e8105 to your computer and use it in GitHub Desktop.
Save florianpircher/d76122568aaf483dc6d60065c72e8105 to your computer and use it in GitHub Desktop.
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