Split or glue together checks for not null and is instance + more intelligent use of filter vs filterTo

#KT-14284 Fixed
 #KT-14286 Fixed
 #KT-14287 Fixed
 #KT-14303 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-10-17 16:27:01 +03:00
parent 53220b980e
commit 89099b93b1
41 changed files with 548 additions and 126 deletions
@@ -1,6 +1,6 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
// IS_APPLICABLE_2: false
// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'"
// INTENTION_TEXT_2: "Replace with 'asSequence()...filter{}.map{}.firstOrNull()'"
fun foo(list: List<Any>, o: Any): Int? {
<caret>for (s in list) {
if (s is String && s.length > 0) {
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'"
// INTENTION_TEXT_2: "Replace with 'asSequence()...filter{}.map{}.firstOrNull()'"
fun foo(list: List<Any>, o: Any): Int? {
return list
.filterIsInstance<String>()
.filter { it.length > 0 }
.map { it.length * 2 }
.firstOrNull()
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '...filter{}.map{}.firstOrNull()'"
// INTENTION_TEXT_2: "Replace with 'asSequence()...filter{}.map{}.firstOrNull()'"
fun foo(list: List<Any>, o: Any): Int? {
return list
.asSequence()
.filterIsInstance<String>()
.filter { it.length > 0 }
.map { it.length * 2 }
.firstOrNull()
}