Inspectopedia Help

Replace 'mapIndexed' with List generator

Reports a mapIndexed call that can be replaced by List generator.

Example:

val a = listOf(1, 2, 3).mapIndexed { i, _ -> i + 42 }

After the quick-fix is applied:

val a = List(listOf(1, 2, 3).size) { i -> i + 42 }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023