Basic support for "add" to collection used inside the loop
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
<caret>for (s in list) {
|
||||
if (s.length > 0) {
|
||||
result.add(s)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<String> {
|
||||
<caret>val result = list.filter { it.length > 0 }
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<Int> {
|
||||
val result = ArrayList<Int>()
|
||||
<caret>for (s in list) {
|
||||
if (s.length > 0)
|
||||
result.add(s.hashCode())
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<Int> {
|
||||
val result = list
|
||||
.filter { it.length > 0 }
|
||||
.map { it.hashCode() }
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<Int> {
|
||||
val result = ArrayList<Int>()
|
||||
<caret>for (s in list) {
|
||||
if (s.length > result.size) {
|
||||
result.add(s.hashCode())
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(list: List<String>): List<Int> {
|
||||
val result = ArrayList<Int>()
|
||||
<caret>list
|
||||
.filter { it.length > result.size }
|
||||
.mapTo(result) { it.hashCode() }
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(map: Map<Int, String>): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
<caret>for (s in map.values) {
|
||||
result.add(s)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.ArrayList
|
||||
|
||||
fun foo(map: Map<Int, String>): List<String> {
|
||||
<caret>val result = map.values.toList()
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.HashSet
|
||||
|
||||
fun foo(map: Map<Int, String>): Collection<String> {
|
||||
val result = HashSet<String>()
|
||||
<caret>for (s in map.values) {
|
||||
result.add(s)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.HashSet
|
||||
|
||||
fun foo(map: Map<Int, String>): Collection<String> {
|
||||
<caret>val result = map.values.toSet()
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.HashSet
|
||||
|
||||
fun foo(map: Map<Int, String>): Collection<Int> {
|
||||
val result = HashSet<Int>()
|
||||
<caret>for (s in map.values) {
|
||||
result.add(s.length)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
import java.util.HashSet
|
||||
|
||||
fun foo(map: Map<Int, String>): Collection<Int> {
|
||||
<caret>val result = map.values
|
||||
.map { it.length }
|
||||
.toSet()
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user