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]

< Closures   |   Structures >

© 2019 SyntaxDB. All Rights Reserved.