Junior — Middle
What is the result returned by the map function when called on a collection or data stream?
sobes.tech AI
Answer from AI
The map function, when called on a collection or data stream, returns a new collection where each element is the result of applying the given function to the corresponding element of the original collection.
For example, if you have a list of numbers [1, 2, 3] and call map with a function that multiplies by 2, the result will be [2, 4, 6].
Example in Kotlin:
val numbers = listOf(1, 2, 3)
val doubled = numbers.map { it * 2 } // [2, 4, 6]
Thus, map transforms the elements without modifying the original collection.