Language
Version: 4
Categories
-
User Program Communication
-
Variables
-
Control Flow
-
Functions
-
Object Oriented Programming
Functions
Map in Swift
Map is a function used to run a closure on an entire sequence.
Syntax
//can also be var
let newSequence = oldSequence.map(closure)
Notes
Types for a map are inferred.
Example
var metres = [1, 3, 5]
metresToCm = metres.map( { (metre) -> Int in metre * 100 } )
#should return [100, 300, 500]