KT-14210 for loop to stdlib: max/min is not recognized if there is additional if

#KT-14210 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-10-14 17:32:35 +03:00
parent 35ed689b9f
commit a89ef54578
6 changed files with 44 additions and 0 deletions
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filter{}.max()'"
fun f(list: List<Int>) {
var result = -1
<caret>for (item in list)
if (item % 2 == 0)
if (result <= item)
result = item
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filter{}.max()'"
fun f(list: List<Int>) {
val <caret>result = list
.filter { it % 2 == 0 }
.max()
?: -1
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'filter{}.max()'"
// INTENTION_TEXT_2: "Replace with 'asSequence().filter{}.max()'"
fun f(list: List<Int>) {
val <caret>result = list
.asSequence()
.filter { it % 2 == 0 }
.max()
?: -1
}