Supported forEachIndexed

This commit is contained in:
Valentin Kipyatkov
2016-05-11 22:52:46 +03:00
parent f28dca1fd5
commit 4094d77782
7 changed files with 54 additions and 6 deletions
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.forEachIndexed{}'"
fun foo(list: List<String>) {
<caret>for ((index, s) in list.withIndex()) {
val s1 = s.substring(1)
println(s1.hashCode() * index)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.forEachIndexed{}'"
fun foo(list: List<String>) {
list
.map { it.substring(1) }
.forEachIndexed { index, s1 -> println(s1.hashCode() * index) }
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'forEachIndexed{}'"
fun foo(list: List<String>) {
<caret>for ((index, s) in list.withIndex()) {
println(s.hashCode() * index)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'forEachIndexed{}'"
fun foo(list: List<String>) {
list.forEachIndexed { index, s -> println(s.hashCode() * index) }
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.forEach{}'"
fun foo(list: List<String>) {
<caret>for ((index, s) in list.withIndex()) {
val x = s.length * index
println(x)
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexed{}.forEach{}'"
fun foo(list: List<String>) {
list
.mapIndexed { index, s -> s.length * index }
.forEach { println(it) }
}