New Intention: Replace for loop with forEach
Replaces an expression of the form “for (i in list) { … }” with an
expression of the form “list.forEach { i -> … }”
This commit is contained in:
committed by
Mikhael Bogdanov
parent
dbb28c571b
commit
33fd82cf45
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun main() {
|
||||
<caret>for (x in 1 rangeTo 2) {
|
||||
x
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
fun main() {
|
||||
(1 rangeTo 2).forEach { x -> x }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
|
||||
<caret>for (x in list) {
|
||||
x
|
||||
x
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
|
||||
list.forEach { x ->
|
||||
x
|
||||
x
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
fun main() {
|
||||
val list = 1..4
|
||||
|
||||
<caret>for (x: Int in list) {
|
||||
x
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun main() {
|
||||
val list = 1..4
|
||||
|
||||
list.forEach {(x: Int) -> x }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
val i = 0
|
||||
|
||||
<caret>for (i in list)
|
||||
i
|
||||
i
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
val i = 0
|
||||
|
||||
list.forEach { i -> i }
|
||||
i
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
|
||||
<caret>for (i in list) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
|
||||
list.forEach { i -> }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
|
||||
<caret>for (x in list) {
|
||||
x
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
val list = 1..4
|
||||
|
||||
list.forEach { x -> x }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun main() {
|
||||
val list = 1..4
|
||||
|
||||
<caret>for (x: Int in list) 11
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun main() {
|
||||
val list = 1..4
|
||||
|
||||
list.forEach {(x: Int) -> 11 }
|
||||
}
|
||||
Reference in New Issue
Block a user