Introduce associateWith and associateWithTo functions

#KT-13814
This commit is contained in:
Ilya Gorbunov
2018-08-20 22:01:12 +03:00
parent 751e844258
commit f367322084
10 changed files with 211 additions and 0 deletions
+8
View File
@@ -1159,6 +1159,14 @@ class StringTest {
assertEquals(listOf('A', 'A', 'B', 'D'), result[true])
}
@Test fun associateWith() = withOneCharSequenceArg("abc") { data ->
val result = data.associateWith { it + 1 }
assertEquals(mapOf('a' to 'b', 'b' to 'c', 'c' to 'd'), result)
val mutableResult = data.drop(1).associateWithTo(result.toMutableMap()) { it - 1 }
assertEquals(mapOf('a' to 'b', 'b' to 'a', 'c' to 'b'), mutableResult)
}
@Test fun joinToString() {
val data = "abcd".toList()
val result = data.joinToString("_", "(", ")")