Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func genericApply<T>(to array: [Int], transform: (Int) -> T) -> [T] {
- var result: [T] = []
- for element in array {
- result.append(transform(element))
- }
- return result
- }
- genericApply(to: arr) { String($0) } //["2", "3", "4", "5"]
Add Comment
Please, Sign In to add comment