swift . map code example
Example: map swift
// A map example which maps each item in this array of numbers
// to its value multiplied by 2.
let array = [1, 2, 3, 4]
// Full closure
print(array.map({ (num: Int) -> Int in return num * 2 }))
// Abbreviated trailing closure, with inferred arguments,
// argument type, and return type.
print(array.map { $0 * 2 })
// Output: [2, 4, 6, 8]