Skip to content

Instantly share code, notes, and snippets.

@seivan
Last active June 7, 2016 18:48
Show Gist options
  • Save seivan/b8e9d2628eb2d6de6c40a89a599eab0c to your computer and use it in GitHub Desktop.
Save seivan/b8e9d2628eb2d6de6c40a89a599eab0c to your computer and use it in GitHub Desktop.
Doesn't help with the "temp" variables not being passed over, but allows flatMap to work like Swift 3.
extension CollectionType {
private func flatMap<S : SequenceType>(transform: (Self.Generator.Element) throws -> S) rethrows -> Set<S.Generator.Element> {
return
Set(
try self
.map(transform)
.filter { $0 != nil }
.map { $0! }
.flatten()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment