Inspectopedia Help

Loop can be replaced with stdlib operations

Reports for loops that can be replaced with a sequence of stdlib operations (like map, filter, and so on).

Example:

fun foo(list: List<String>): List<Int> { val result = ArrayList<Int>() for (s in list) { if (s.length > 0) result.add(s.hashCode()) } return result }

After the quick-fix is applied:

fun foo(list: List<String>): List<Int> { val result = list .filter { it.length > 0 } .map { it.hashCode() } return result }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023