Add onEachIndexed similar to forEachIndexed #KT-37161

This commit is contained in:
Abduqodiri Qurbonzoda
2020-04-01 02:52:25 +03:00
parent 57d390bab0
commit 4a7b1b210a
14 changed files with 368 additions and 17 deletions
@@ -313,6 +313,17 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
assertStaticTypeIs<ArrayList<Int>>(arrayListOf(1, 2, 3).onEach { })
}
@Test
fun onEachIndexed() {
var count = 0
val newData = data.onEachIndexed { i, e -> count += i + e.length }
assertEquals(7, count)
assertSame(data, newData)
// static types test
assertStaticTypeIs<ArrayList<Int>>(arrayListOf(1, 2, 3).onEachIndexed { _, _ -> })
}
@Test
fun contains() {
assertTrue(data.contains("foo"))