Last active
April 11, 2018 21:53
-
-
Save BasThomas/d03e138a9bb098d347c52ca7d6870a45 to your computer and use it in GitHub Desktop.
Backward compatibility for `compactMap` in Swift 4.0.
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
#if swift(>=4.1) | |
#else | |
extension Collection { | |
func compactMap<ElementOfResult>( | |
_ transform: (Element) throws -> ElementOfResult? | |
) rethrows -> [ElementOfResult] { | |
return try flatMap(transform) | |
} | |
} | |
#endif |
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
#if swift(>=4.1) | |
#elseif swift(>=4.2) | |
#warning("Remove this once we've updated.") | |
#else | |
extension Collection { | |
func compactMap<ElementOfResult>( | |
_ transform: (Element) throws -> ElementOfResult? | |
) rethrows -> [ElementOfResult] { | |
return try flatMap(transform) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment