The enumerate function returns a tuple for each item in the array composed of the index and the value for that item.
The map function returns an array of elements built from the results of applying a provided transforming closure for each element in the array.
Declaration:
func map<U>(transform: (T) -> U) -> [U]
var numbers = [1, 2, 3]
numbers = map(numbers) { (index, element) in
index + element
} //[1, 3, 5]
That is good. Works.
var numbers = [1, 2, 3]
var result = map(enumerate(numbers)) { (index, element) in
index + element
} //[1, 3, 5]
map
expects an array as a first parameter, but I put there the tuple as a result of enumerate fnction.
The question is: WHY IT WORKS?