Elvis operator supported for all cases of find
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>) {
|
||||
var result = ""
|
||||
<caret>for (s in list) {
|
||||
if (s.length > 0) {
|
||||
result = bar(s)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(s: String): String = s
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>) {
|
||||
<caret>val result = list.firstOrNull { it.length > 0 }?.let { bar(it) } ?: ""
|
||||
}
|
||||
|
||||
fun bar(s: String): String = s
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>): Int {
|
||||
<caret>for (s in list) {
|
||||
if (s.isNotEmpty()) {
|
||||
return s.length
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(list: List<String>): Int {
|
||||
<caret>return list.firstOrNull { it.isNotEmpty() }?.length ?: -1
|
||||
}
|
||||
Reference in New Issue
Block a user