map

Common
JVM
JS
Native
1.0
inline fun <T, R> Array<out T>.map(
    transform: (T) -> R
): List<R>

(source)
inline fun <R> ByteArray.map(transform: (Byte) -> R): List<R>
(source)
inline fun <R> ShortArray.map(
    transform: (Short) -> R
): List<R>

(source)
inline fun <R> IntArray.map(transform: (Int) -> R): List<R>
(source)
inline fun <R> LongArray.map(transform: (Long) -> R): List<R>
(source)
inline fun <R> FloatArray.map(
    transform: (Float) -> R
): List<R>

(source)
inline fun <R> DoubleArray.map(
    transform: (Double) -> R
): List<R>

(source)
inline fun <R> BooleanArray.map(
    transform: (Boolean) -> R
): List<R>

(source)
inline fun <R> CharArray.map(transform: (Char) -> R): List<R>
(source)
@ExperimentalUnsignedTypes inline fun <R> UIntArray.map(
    transform: (UInt) -> R
): List<R>

(source)
@ExperimentalUnsignedTypes inline fun <R> ULongArray.map(
    transform: (ULong) -> R
): List<R>

(source)
@ExperimentalUnsignedTypes inline fun <R> UByteArray.map(
    transform: (UByte) -> R
): List<R>

(source)
@ExperimentalUnsignedTypes inline fun <R> UShortArray.map(
    transform: (UShort) -> R
): List<R>

(source)

Returns a list containing the results of applying the given transform function to each element in the original array.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val numbers = listOf(1, 2, 3)
println(numbers.map { it * it }) // [1, 4, 9]
//sampleEnd
}
Common
JVM
JS
Native
1.0
inline fun <T, R> Iterable<T>.map(
    transform: (T) -> R
): List<R>

(source)

Returns a list containing the results of applying the given transform function to each element in the original collection.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val numbers = listOf(1, 2, 3)
println(numbers.map { it * it }) // [1, 4, 9]
//sampleEnd
}
Common
JVM
JS
Native
1.0
inline fun <K, V, R> Map<out K, V>.map(
    transform: (Entry<K, V>) -> R
): List<R>

(source)

Returns a list containing the results of applying the given transform function to each entry in the original map.

import kotlin.test.*
import java.util.*

fun main(args: Array<String>) {
//sampleStart
val peopleToAge = mapOf("Alice" to 20, "Bob" to 21)
println(peopleToAge.map { (name, age) -> "$name is $age years old" }) // [Alice is 20 years old, Bob is 21 years old]
println(peopleToAge.map { it.value }) // [20, 21]
//sampleEnd
}