Last active
June 7, 2016 18:48
-
-
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.
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 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