Ever wondered what map() actually does? π€
Letβs break it down in the simplest way possible π
π§ What is map()?
map() is used to transform a list into another list.
π It takes each item
π Applies some logic
π Returns a new list
π£ Kotlin Example
val numbers = listOf(1, 2, 3)
val doubled = numbers.map {
it * 2
}
println(doubled) // [2, 4, 6]
π£ Dart Example
var numbers = [1, 2, 3];
var doubled = numbers.map((n) => n * 2).toList();
print(doubled); // [2, 4, 6]
Top comments (0)