Deprecate withIndicies(), introduce optimized and fixed withIndex and forEachIndexed()

This commit is contained in:
Ilya Ryzhenkov
2014-11-06 20:35:33 +03:00
parent b5fb09b8bc
commit e890c2ee0d
8 changed files with 273 additions and 6 deletions
@@ -163,6 +163,20 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
assertEquals(arrayListOf(3, 3), lengths)
}
Test
fun mapIndexed() {
val shortened = data.mapIndexed { (index, value)-> value.substring(0..index) }
assertEquals(2, shortened.size())
assertEquals(arrayListOf("f", "ba"), shortened)
}
Test
fun withIndex() {
val indexed = data.withIndex().map { it.value.substring(0..it.index) }
assertEquals(2, indexed.size())
assertEquals(arrayListOf("f", "ba"), indexed)
}
Test
fun max() {
expect("foo") { data.max() }