Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension SequenceType where Generator.Element: Hashable {
var uniques: [Generator.Element] {
var past = Set<Generator.Element>()
return self.filter {
element in
if past.contains(element) {
return false
} else {
past.insert(element)
return true
}
}
}
var freqs: [Generator.Element:Int] {
var accu: [Generator.Element:Int] = [:]
for element in self { accu[element] = accu[element]?.successor() ?? 1 }
return accu
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.