Added stdlib function withIndices() converting sequence (Iterable) to sequence of index-value pairs.

#KT-1195 fixed
This commit is contained in:
Evgeny Gerashchenko
2012-02-27 17:43:04 +04:00
parent 12f7d463ad
commit 4c70d341b1
2 changed files with 48 additions and 1 deletions
+11
View File
@@ -27,4 +27,15 @@ class ListTest() : TestSupport() {
val t = data.last
assertEquals("bar", t)
}
fun testWithIndices() {
val withIndices = data.withIndices()
var index = 0
for (withIndex in withIndices) {
assertEquals(withIndex._1, index)
assertEquals(withIndex._2, data[index])
index++
}
assertEquals(data.size(), index)
}
}