Array map vs. forEach in Swift

Viewed 15522

In Swift arrays you can do:

var myArray = [1,2,3,4]

myArray.forEach() { print($0 * 2) }

myArray.map() { print($0 * 2) }

They both do the same thing. The only difference is .map also returns an array of voids as well, [(),(),(),()], which gets unused. Does that mean .map performs worse than .forEach when it's not assigning to anything?

3 Answers
Related