stdlib: stream() for Map #KT-6547 Fixed
This commit is contained in:
@@ -119,6 +119,17 @@ public fun <T> Iterable<T>.stream(): Stream<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream from the given collection
|
||||
*/
|
||||
public fun <K, V> Map<K, V>.stream(): Stream<Map.Entry<K, V>> {
|
||||
return object : Stream<Map.Entry<K, V>> {
|
||||
override fun iterator(): Iterator<Map.Entry<K, V>> {
|
||||
return this@stream.iterator()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream from the given collection
|
||||
*/
|
||||
|
||||
@@ -66,6 +66,12 @@ class MapTest {
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.join(","))
|
||||
}
|
||||
|
||||
test fun stream() {
|
||||
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
|
||||
val named = map.stream().filter { it.key == "name" }.single()
|
||||
assertEquals("James", named.value)
|
||||
}
|
||||
|
||||
test fun iterateWithProperties() {
|
||||
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
|
||||
val list = arrayListOf<String>()
|
||||
|
||||
Reference in New Issue
Block a user