Supported filterIndexedTo

This commit is contained in:
Valentin Kipyatkov
2016-04-21 20:51:33 +03:00
parent 7c473e7159
commit 318f3dfdd8
7 changed files with 78 additions and 8 deletions
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexedTo(){}'"
fun foo(list: List<String>, target: MutableList<String>) {
<caret>for ((index, s) in list.withIndex()) {
if (s.length > index)
target.add(s)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexedTo(){}'"
fun foo(list: List<String>, target: MutableList<String>) {
<caret>list.filterIndexedTo(target) { index, s -> s.length > index }
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filterIndexedTo(){}'"
import java.util.ArrayList
fun foo(list: List<String>): List<String> {
val result = ArrayList<String>(1000)
<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 'filterIndexedTo(){}'"
import java.util.ArrayList
fun foo(list: List<String>): List<String> {
val <caret>result = list.filterIndexedTo(ArrayList<String>(1000)) { index, s -> s.length > index }
return result
}
@@ -1,5 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= filterIndexed{}.filterIndexed{}'"
// INTENTION_TEXT: "Replace with 'filterIndexed{}.filterIndexedTo(){}'"
fun foo(list: List<String>, target: MutableCollection<String>) {
var j = 0
<caret>for ((i, s) in list.withIndex()) {
@@ -1,7 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= filterIndexed{}.filterIndexed{}'"
// INTENTION_TEXT: "Replace with 'filterIndexed{}.filterIndexedTo(){}'"
fun foo(list: List<String>, target: MutableCollection<String>) {
<caret>target += list
<caret>list
.filterIndexed { i, s -> s.length <= i }
.filterIndexed { j, s -> s.length % j == 0 }
.filterIndexedTo(target) { j, s -> s.length % j == 0 }
}