Introduce T.addTo(MutableCollection<T>), mapNotNull and mapIndexedNotNull extensions.

#KT-4410 Fixed
This commit is contained in:
Ilya Gorbunov
2015-11-07 06:50:19 +03:00
parent 008a8059cf
commit 9323f61eaf
10 changed files with 398 additions and 145 deletions
@@ -129,6 +129,13 @@ class MapTest {
assertEquals(listOf("beer rocks", "Mells rocks"), list)
}
@test fun mapNotNull() {
val m1 = mapOf("a" to 1, "b" to null)
val list = m1.mapNotNull { it.value?.let { v -> "${it.key}$v" } }
assertEquals(listOf("a1"), list)
}
@test fun mapValues() {
val m1 = mapOf("beverage" to "beer", "location" to "Mells")
val m2 = m1.mapValues { it.value + "2" }