Skip to content

Instantly share code, notes, and snippets.

@swiftyfinch
Last active May 16, 2021 09:49
Show Gist options
  • Save swiftyfinch/7ebb2336a4ee3f81b722a5889c7be9d0 to your computer and use it in GitHub Desktop.
Save swiftyfinch/7ebb2336a4ee3f81b722a5889c7be9d0 to your computer and use it in GitHub Desktop.
Inserts an collection to Set (It's not the same as union)
extension Set {
/// Inserts other collection to current. It works like the `insert` method, but not like the `union`.
func inserts<S: Sequence>(_ other: S) -> Self where S.Element == Element {
var new = self
other.forEach { new.insert($0) }
return new
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment