Skip to content

Instantly share code, notes, and snippets.

@knowsudhanshu
Last active June 19, 2021 11:25
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/e45c6ce67d5c8dcd32586c252ac81244 to your computer and use it in GitHub Desktop.
Save knowsudhanshu/e45c6ce67d5c8dcd32586c252ac81244 to your computer and use it in GitHub Desktop.
myMap Example
extension Sequence {
func myMap<T>(_ operation: (Element) -> T) -> [T] {
var arrayAfterOperatedValues: [T] = []
for item in self {
/// Apply operation on each element (as map(_:) does)
let operatedValue = operation(item)
arrayAfterOperatedValues.append(operatedValue)
}
return arrayAfterOperatedValues
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment