Do not generate redundant .toList()
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterIndexed{}'"
|
||||
import java.util.*
|
||||
|
||||
fun foo(list: List<String>): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
if (s.length > index) {
|
||||
result.add(s)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterIndexed{}'"
|
||||
import java.util.*
|
||||
|
||||
fun foo(list: List<String>): List<String> {
|
||||
val <caret>result = list.filterIndexed { index, s -> s.length > index }
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull()'"
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String?>): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
<caret>for (s in list) {
|
||||
if (s != null) {
|
||||
result.add(s)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull()'"
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String?>): List<String> {
|
||||
val <caret>result = list.filterNotNull()
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filter{}.map{}'"
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<Int> {
|
||||
val result = ArrayList<Int>()
|
||||
<caret>for (s in list) {
|
||||
if (s.length > 0) {
|
||||
val h = s.hashCode()
|
||||
result.add(h)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filter{}.map{}'"
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<Int> {
|
||||
val <caret>result = list
|
||||
.filter { it.length > 0 }
|
||||
.map { it.hashCode() }
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user