I have recommendation good examples for article. The success of the generic function return a new array containing the values transformed. Of Course You can do with closure and map. But What If I want to use GENERIC ? Here you are.

func square(_ a: Int) -> Int {    
return Int(a * a)
}
genericMap<T, U>(array: [T], transformation: (T) -> U) -> [U] {
var newArray = [U]()
for values in array {
newArray.append(transformation(values))
}
return newArray
}
genericMap(array: [3,5,6,7,7,8,8], transformation: square)

Written by

Health Research Program’s iOS Developer, currently lives in Washington, D.C http://www.about.me/durul

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store