Created
June 20, 2021 10:50
-
-
Save knowsudhanshu/187d5260a710e5d9bf9e4b5d2dbb5dd3 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 Sequence { | |
func myCompactMap<T>(_ operation: (Element) -> T?) -> [T] { | |
var output: [T] = [] | |
for item in self { | |
if let value = operation(item) { | |
output.append(value) | |
} | |
} | |
return output | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment