takeWhile supported

This commit is contained in:
Valentin Kipyatkov
2016-04-21 22:06:09 +03:00
parent 9ff0f4d736
commit 3f563f7058
6 changed files with 84 additions and 5 deletions
+8
View File
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= takeWhile{}'"
fun foo(list: List<String>, target: MutableCollection<String>) {
<caret>for (s in list) {
if (s.isEmpty()) break
target.add(s)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= takeWhile{}'"
fun foo(list: List<String>, target: MutableCollection<String>) {
<caret>target += list.takeWhile { !it.isEmpty() }
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= flatMap{}.takeWhile{}'"
fun foo(list: List<String>, target: MutableCollection<Int>) {
Outer@
<caret>for (s in list) {
for (i in s.indices) {
if (i > 1000) break@Outer
target.add(i)
}
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= flatMap{}.takeWhile{}'"
fun foo(list: List<String>, target: MutableCollection<Int>) {
<caret>target += list
.flatMap { it.indices }
.takeWhile { it <= 1000 }
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(list: List<String>, target: MutableCollection<Int>) {
<caret>for (s in list) {
for (i in s.indices) {
if (i > 1000) break
target.add(i)
}
}
}