Last active
June 19, 2021 11:25
-
-
Save knowsudhanshu/e45c6ce67d5c8dcd32586c252ac81244 to your computer and use it in GitHub Desktop.
myMap Example
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 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