Call chain --> Sequence: introduce "call chain length" parameter

#KT-26571 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-09-27 10:40:44 +03:00
committed by Mikhail Glukhikh
parent a43be4cbe8
commit 920c200693
12 changed files with 76 additions and 23 deletions
@@ -1,5 +1,7 @@
// PROBLEM: Call chain on collection could be converted into 'Sequence' to increase performance
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
// WITH_RUNTIME
fun test(): List<Int> {
return listOf(1, 2, 3).<caret>filter { it > 1 }.map { it * 2 }
return listOf(1, 2, 3).<caret>filter { it > 1 }.map { it * 2 }.map { it * 3 }.map { it * 4 }.map { it * 5 }
}
@@ -1,5 +1,7 @@
// PROBLEM: Call chain on collection could be converted into 'Sequence' to increase performance
// HIGHLIGHT: GENERIC_ERROR_OR_WARNING
// WITH_RUNTIME
fun test(): List<Int> {
return listOf(1, 2, 3).asSequence().filter { it > 1 }.map { it * 2 }.toList()
return listOf(1, 2, 3).asSequence().filter { it > 1 }.map { it * 2 }.map { it * 3 }.map { it * 4 }.map { it * 5 }.toList()
}
@@ -1,7 +1,10 @@
// HIGHLIGHT: INFORMATION
// WITH_RUNTIME
fun test(list: List<Int>): List<Int> {
return list
.filter<caret> { it > 1 }
.map { it * 2 }
.map { it * 3 }
.map { it * 4 }
}
@@ -1,3 +1,4 @@
// HIGHLIGHT: INFORMATION
// WITH_RUNTIME
fun test(list: List<Int>): List<Int> {
@@ -5,5 +6,7 @@ fun test(list: List<Int>): List<Int> {
.asSequence()
.filter { it > 1 }
.map { it * 2 }
.map { it * 3 }
.map { it * 4 }
.toList()
}