Introduce "Call chain on collection should be converted into 'Sequence'"
So #KT-15476 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
76a98c8e67
commit
108dea5b46
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.collections.ConvertCallChainIntoSequenceInspection
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Pair<List<Int>, List<Int>>> {
|
||||
return list
|
||||
.<caret>chunked(1)
|
||||
.distinct()
|
||||
.distinctBy { it }
|
||||
.drop(1)
|
||||
.dropWhile { true }
|
||||
.filter { true }
|
||||
.filterIndexed { index, list -> true }
|
||||
.filterIsInstance<Int>()
|
||||
.filterNot { true }
|
||||
.filterNotNull()
|
||||
.map { it }
|
||||
.mapIndexed { index, i -> i }
|
||||
.mapIndexedNotNull { index, i -> i }
|
||||
.mapNotNull { it }
|
||||
.minus(1)
|
||||
.minusElement(1)
|
||||
.onEach {}
|
||||
.plus(1)
|
||||
.plusElement(1)
|
||||
.requireNoNulls()
|
||||
.sorted()
|
||||
.sortedBy { it }
|
||||
.sortedByDescending { it }
|
||||
.sortedDescending()
|
||||
.sortedWith(Comparator { o1, o2 -> 0 })
|
||||
.take(1)
|
||||
.takeWhile { true }
|
||||
.windowed(1, 1, true)
|
||||
.zipWithNext()
|
||||
.zipWithNext { a, b -> a }
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Pair<List<Int>, List<Int>>> {
|
||||
return list
|
||||
.asSequence()
|
||||
.chunked(1)
|
||||
.distinct()
|
||||
.distinctBy { it }
|
||||
.drop(1)
|
||||
.dropWhile { true }
|
||||
.filter { true }
|
||||
.filterIndexed { index, list -> true }
|
||||
.filterIsInstance<Int>()
|
||||
.filterNot { true }
|
||||
.filterNotNull()
|
||||
.map { it }
|
||||
.mapIndexed { index, i -> i }
|
||||
.mapIndexedNotNull { index, i -> i }
|
||||
.mapNotNull { it }
|
||||
.minus(1)
|
||||
.minusElement(1)
|
||||
.onEach {}
|
||||
.plus(1)
|
||||
.plusElement(1)
|
||||
.requireNoNulls()
|
||||
.sorted()
|
||||
.sortedBy { it }
|
||||
.sortedByDescending { it }
|
||||
.sortedDescending()
|
||||
.sortedWith(Comparator { o1, o2 -> 0 })
|
||||
.take(1)
|
||||
.takeWhile { true }
|
||||
.windowed(1, 1, true)
|
||||
.zipWithNext()
|
||||
.zipWithNext { a, b -> a }
|
||||
.toList()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): Int {
|
||||
return list // comment1
|
||||
.<caret>filter { it > 1 } // comment2
|
||||
.map { it * 2 } // comment3
|
||||
.sum() // comment4
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): Int {
|
||||
return list // comment1
|
||||
.asSequence()
|
||||
.filter { it > 1 } // comment2
|
||||
.map { it * 2 } // comment3
|
||||
.sum() // comment4
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list // comment1
|
||||
.<caret>filter { it > 1 } // comment2
|
||||
.map { it * 2 } // comment3
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list // comment1
|
||||
.asSequence()
|
||||
.filter { it > 1 } // comment2
|
||||
.map { it * 2 }
|
||||
.toList() // comment3
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list.<caret>filter { it > 1 }
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list.filter { it > 2 }.dropLast(1).<caret>filter { it > 2 }
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.reversed()
|
||||
.map { it + 1 }
|
||||
.<caret>map { it + 1 }
|
||||
.dropLast(1)
|
||||
.takeLast(2)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>?): List<Int>? {
|
||||
return list
|
||||
?.<caret>filter { it > 1 }
|
||||
?.map { it * 2 }
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>?): List<Int>? {
|
||||
return list
|
||||
?.asSequence()
|
||||
?.filter { it > 1 }
|
||||
?.map { it * 2 }
|
||||
?.toList()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>?): List<Int>? {
|
||||
return list?.filter { it > 1 }!!.<caret>filter { it > 2 }.filter { it > 3 }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>?): List<Int>? {
|
||||
return list?.filter { it > 1 }!!.asSequence().filter { it > 2 }.filter { it > 3 }.toList()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.<caret>filter { it > 1 }
|
||||
.mapNotNull {
|
||||
if (it == 2) return emptyList()
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.<caret>filter { it > 1 }
|
||||
.mapNotNull {
|
||||
if (it == 2) return@mapNotNull null
|
||||
it * 2
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.asSequence()
|
||||
.filter { it > 1 }
|
||||
.mapNotNull {
|
||||
if (it == 2) return@mapNotNull null
|
||||
it * 2
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): List<Int> {
|
||||
return listOf(1, 2, 3).<caret>filter { it > 1 }.map { it * 2 }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): List<Int> {
|
||||
return listOf(1, 2, 3).asSequence().filter { it > 1 }.map { it * 2 }.toList()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.filter<caret> { it > 1 }
|
||||
.map { it * 2 }
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.asSequence()
|
||||
.filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.toList()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.reversed()
|
||||
.<caret>map { it + 1 }
|
||||
.map { it + 1 }
|
||||
.dropLast(1)
|
||||
.takeLast(2)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<Int>): List<Int> {
|
||||
return list
|
||||
.reversed()
|
||||
.asSequence()
|
||||
.map { it + 1 }
|
||||
.map { it + 1 }
|
||||
.toList()
|
||||
.dropLast(1)
|
||||
.takeLast(2)
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(foo: Foo): List<Int> {
|
||||
return foo.getList()
|
||||
.<caret>filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
}
|
||||
|
||||
class Foo {
|
||||
fun getList(): List<Int> = listOf(1, 2, 3)
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(foo: Foo): List<Int> {
|
||||
return foo.getList()
|
||||
.asSequence()
|
||||
.filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.toList()
|
||||
}
|
||||
|
||||
class Foo {
|
||||
fun getList(): List<Int> = listOf(1, 2, 3)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
return listOf(1, 2, 3)
|
||||
.<caret>filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.sum()
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
return listOf(1, 2, 3)
|
||||
.asSequence()
|
||||
.filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.sum()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
return listOf(1, 2, 3)
|
||||
.<caret>filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.binarySearch(4)
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
return listOf(1, 2, 3)
|
||||
.asSequence()
|
||||
.filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.toList()
|
||||
.binarySearch(4)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
return listOf(1, 2, 3)
|
||||
.<caret>filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.let {
|
||||
it.binarySearch(1)
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(): Int {
|
||||
return listOf(1, 2, 3)
|
||||
.asSequence()
|
||||
.filter { it > 1 }
|
||||
.map { it * 2 }
|
||||
.toList()
|
||||
.let {
|
||||
it.binarySearch(1)
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<List<Int>>): List<Int> {
|
||||
return list
|
||||
.<caret>filter { it.count() > 2 }
|
||||
.map { it + it }
|
||||
.flatMap { it + it }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test(list: List<List<Int>>): List<Int> {
|
||||
return list
|
||||
.asSequence()
|
||||
.filter { it.count() > 2 }
|
||||
.map { it + it }
|
||||
.toList()
|
||||
.flatMap { it + it }
|
||||
}
|
||||
Reference in New Issue
Block a user