Created
January 14, 2015 15:39
-
-
Save Francescu/8d6015c1c49617cff169 to your computer and use it in GitHub Desktop.
mapSome
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 Array { | |
func mapSome<R>(transform: T -> R?) -> [R] { | |
return self.reduce([R]()) { | |
if let unwrappedValue = transform($1) { | |
return $0 + [unwrappedValue] | |
} | |
return $0 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment