Don't generate .forEach { return } when converting loop to call chain

#KT-17161 Fixed
This commit is contained in:
Dmitry Jemerov
2017-12-14 17:37:05 +01:00
parent b775b901cc
commit 09d27ca61c
7 changed files with 26 additions and 25 deletions
@@ -1,6 +1,6 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.forEach{}'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filter{}.forEach{}'"
// IS_APPLICABLE: false
// IS_APPLICABLE_2: false
fun foo(list: List<String?>): String? {
<caret>for (s in list) {
if (s == null || s.isNotEmpty()) {
@@ -1,9 +0,0 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.forEach{}'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filter{}.forEach{}'"
fun foo(list: List<String?>): String? {
list
.filter { it == null || it.isNotEmpty() }
.forEach { return it }
return ""
}
@@ -1,10 +0,0 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.forEach{}'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filter{}.forEach{}'"
fun foo(list: List<String?>): String? {
list
.asSequence()
.filter { it == null || it.isNotEmpty() }
.forEach { return it }
return ""
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
// IS_APPLICABLE_2: false
fun foo(l: List<() -> Boolean>) {
<caret>for (i in 0 until l.size) {
if (l[i]()) {
return
}
}
}