Skip to content

Instantly share code, notes, and snippets.

@knowsudhanshu
Created June 20, 2021 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knowsudhanshu/187d5260a710e5d9bf9e4b5d2dbb5dd3 to your computer and use it in GitHub Desktop.
Save knowsudhanshu/187d5260a710e5d9bf9e4b5d2dbb5dd3 to your computer and use it in GitHub Desktop.
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