Sobes.tech
Junior — Middle

Can you give examples of map functions and explain their usage?

sobes.tech AI

Answer from AI

The map functions are higher-order operations that apply a given function to each element of a collection and return a new collection with the results.

Example in Kotlin (Android):

val numbers = listOf(1, 2, 3, 4)
val squares = numbers.map { it * it } // [1, 4, 9, 16]

Here, map takes each element of the list numbers, applies the lambda it * it, and returns a new list with the squares.

Using map helps write clean and declarative code, avoiding explicit loops and mutable variables.

Can you give examples of map functions and explain… - sobes.tech