Improve onEach templates.

Add new functions to reference API.
Add tests for onEach
  #KT-8220
This commit is contained in:
Ilya Gorbunov
2016-10-01 03:51:59 +03:00
parent 5bde230d4a
commit dc57d69085
10 changed files with 115 additions and 14 deletions
@@ -98,6 +98,19 @@ class MapTest {
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
}
@Test
fun onEach() {
val map = mutableMapOf("beverage" to "beer", "location" to "Mells")
val result = StringBuilder()
val newMap = map.onEach { result.append(it.key).append("=").append(it.value).append(";") }
assertEquals("beverage=beer;location=Mells;", result.toString())
assertTrue(map === newMap)
// static types test
val m: HashMap<String, String> = hashMapOf("a" to "b").onEach { }
}
@Test fun stream() {
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
val named = map.asSequence().filter { it.key == "name" }.single()