Supported mapIndexedTo and mapIndexedNotNullTo

This commit is contained in:
Valentin Kipyatkov
2016-04-22 12:12:12 +03:00
parent 2652ea4233
commit b6e05e058e
10 changed files with 61 additions and 22 deletions
@@ -1,5 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= ...filterNot{}.mapIndexed{}'"
// INTENTION_TEXT: "Replace with 'flatMap{}.filterNot{}.mapIndexedTo(){}'"
fun foo(list: List<String>, target: MutableCollection<Int>) {
var i = 0
<caret>for (s in list) {
@@ -1,8 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= ...filterNot{}.mapIndexed{}'"
// INTENTION_TEXT: "Replace with 'flatMap{}.filterNot{}.mapIndexedTo(){}'"
fun foo(list: List<String>, target: MutableCollection<Int>) {
<caret>target += list
<caret>list
.flatMap { it.indices }
.filterNot { it == 10 }
.mapIndexed { i, j -> i + j }
.mapIndexedTo(target) { i, j -> i + j }
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedNotNullTo(){}'"
fun foo(list: List<String?>, target: MutableList<Int>) {
<caret>for ((index, s) in list.withIndex()) {
val length = s?.substring(index)?.length
if (length == null) continue
target.add(length)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedNotNullTo(){}'"
fun foo(list: List<String?>, target: MutableList<Int>) {
<caret>list.mapIndexedNotNullTo(target) { index, s -> s?.substring(index)?.length }
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedNotNullTo(){}'"
fun foo(list: List<String?>, target: MutableList<Int>) {
<caret>for ((index, s) in list.withIndex()) {
val length = s?.substring(index)?.length ?: continue
target.add(length)
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedNotNullTo(){}'"
fun foo(list: List<String?>, target: MutableList<Int>) {
<caret>list.mapIndexedNotNullTo(target) { index, s -> s?.substring(index)?.length }
}
@@ -1,5 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= mapIndexed{}'"
// INTENTION_TEXT: "Replace with 'mapIndexedTo(){}'"
fun foo(list: List<String>, target: MutableList<Int>) {
<caret>for ((index, s) in list.withIndex()) {
target.add(s.hashCode() * index)
@@ -0,0 +1,5 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedTo(){}'"
fun foo(list: List<String>, target: MutableList<Int>) {
<caret>list.mapIndexedTo(target) { index, s -> s.hashCode() * index }
}
@@ -1,5 +0,0 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with '+= mapIndexed{}'"
fun foo(list: List<String>, target: MutableList<Int>) {
<caret>target += list.mapIndexed { index, s -> s.hashCode() * index }
}