Supported other patterns for mapNotNull

This commit is contained in:
Valentin Kipyatkov
2016-04-22 11:48:10 +03:00
parent a6132c7db9
commit 8c7cdf1bf8
5 changed files with 39 additions and 0 deletions
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedNotNull{}.mapTo(){}'"
fun foo(list: List<String?>, target: MutableList<String>) {
<caret>for ((index, s) in list.withIndex()) {
val length = s?.substring(index)?.length
if (length == null) continue
target.add(length.toString())
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapIndexedNotNull{}.mapTo(){}'"
fun foo(list: List<String?>, target: MutableList<String>) {
<caret>list
.mapIndexedNotNull { index, s -> s?.substring(index)?.length }
.mapTo(target) { it.toString() }
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapNotNull{}.mapTo(){}'"
fun foo(list: List<String?>, target: MutableList<String>) {
<caret>for (s in list) {
val length = s?.length
if (length == null) continue
target.add(length.toString())
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'mapNotNull{}.mapTo(){}'"
fun foo(list: List<String?>, target: MutableList<String>) {
<caret>list
.mapNotNull { it?.length }
.mapTo(target) { it.toString() }
}