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

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Kotlin, 241.16690-IJ

Last modified: 29 April 2024