Initial support for indexed transformations
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterIndexed{}.any()'"
|
||||
fun foo(list: List<String>) {
|
||||
var found = false
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
if (s.length > index) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterIndexed{}.any()'"
|
||||
fun foo(list: List<String>) {
|
||||
val <caret>found = list
|
||||
.filterIndexed { index, s -> s.length > index }
|
||||
.any()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterIndexed{}.firstOrNull()'"
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
if (s.length > index) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterIndexed{}.firstOrNull()'"
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>return list
|
||||
.filterIndexed { index, s -> s.length > index }
|
||||
.firstOrNull()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'mapIndexed{}.flatMap{}.firstOrNull{}'"
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
for (line in s.lines().take(index)) {
|
||||
if (line.isNotBlank()) return line
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'mapIndexed{}.flatMap{}.firstOrNull{}'"
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>return list
|
||||
.mapIndexed { index, s -> s.lines().take(index) }
|
||||
.flatMap { it }
|
||||
.firstOrNull { it.isNotBlank() }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'map{}.filterIndexed{}.firstOrNull()'"
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
val l = s.length
|
||||
if (l > index) {
|
||||
return l
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'map{}.filterIndexed{}.firstOrNull()'"
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>return list
|
||||
.map { it.length }
|
||||
.filterIndexed { index, l -> l > index }
|
||||
.firstOrNull()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'mapIndexed{}.firstOrNull{}'"
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
val x = s.length * index
|
||||
if (x > 0) return x
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'mapIndexed{}.firstOrNull{}'"
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>return list
|
||||
.mapIndexed { index, s -> s.length * index }
|
||||
.firstOrNull { it > 0 }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'mapIndexed{}.mapIndexed{}.firstOrNull{}'"
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
val x = s.length * index
|
||||
val y = x + index
|
||||
if (y > 0) return y
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'mapIndexed{}.mapIndexed{}.firstOrNull{}'"
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>return list
|
||||
.mapIndexed { index, s -> s.length * index }
|
||||
.mapIndexed { index, x -> x + index }
|
||||
.firstOrNull { it > 0 }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with '+= mapIndexed{}'"
|
||||
fun foo(list: List<String>, target: MutableList<Int>) {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
target.add(s.hashCode() * index)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with '+= mapIndexed{}'"
|
||||
fun foo(list: List<String>, target: MutableList<Int>) {
|
||||
<caret>target += list.mapIndexed { index, s -> s.hashCode() * index }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
fun foo(list: List<String>): Int? {
|
||||
<caret>for ((index, s) in list.withIndex()) {
|
||||
if (s.isBlank()) continue
|
||||
val x = s.length * index
|
||||
if (x > 1000) return x
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user