Merging subsequent .filter()'s
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>for (s in list) {
|
||||
if (s.isEmpty()) continue
|
||||
if (s.length < 10 && s != "abc") {
|
||||
if (s == "def") continue
|
||||
val s1 = s + "x"
|
||||
return s1
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>): String? {
|
||||
return list
|
||||
.filter { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" }
|
||||
.map { it + "x" }
|
||||
.firstOrNull()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>for (s in list) {
|
||||
if (s.isEmpty()) continue
|
||||
if (s.length < 10 && s != "abc") {
|
||||
if (s == "def") continue
|
||||
return s
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>): String? {
|
||||
<caret>return list.firstOrNull { !it.isEmpty() && it.length < 10 && it != "abc" && it != "def" }
|
||||
}
|
||||
Reference in New Issue
Block a user