Skip to content

Instantly share code, notes, and snippets.

@Francescu
Created January 14, 2015 15:39
Show Gist options
  • Save Francescu/8d6015c1c49617cff169 to your computer and use it in GitHub Desktop.
Save Francescu/8d6015c1c49617cff169 to your computer and use it in GitHub Desktop.
mapSome
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