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)