Created
June 29, 2015 18:08
-
-
Save SlaunchaMan/567f0e8ea60fe8f4bc48 to your computer and use it in GitHub Desktop.
Returns an array containing the given array’s items of type U.
This file contains hidden or 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 Array { | |
| func optionalMap<U>(transform: (T) -> U?) -> [U] { | |
| return map(transform).filter { $0 != nil }.map { $0! } | |
| } | |
| func itemsOfKind<U>(kind: U.Type) -> [U] { | |
| return optionalMap { $0 as? U } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment