Created
March 26, 2018 23:56
-
-
Save aronbalog/23488db1e98f5e43be0b415d041a2595 to your computer and use it in GitHub Desktop.
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 flattened<T>() -> [T] where Element == T? { | |
return flatMap { $0 } | |
} | |
} | |
let array: [String?] = [ | |
"gimme", | |
"some", | |
nil, | |
"sugar" | |
] | |
let flattenedArray = array.flattened() | |
// -> ["gimme", "some", "sugar"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment