diff --git a/libraries/stdlib/src/generated/_Streams.kt b/libraries/stdlib/src/generated/_Streams.kt index 040336167b6..87955f78af6 100644 --- a/libraries/stdlib/src/generated/_Streams.kt +++ b/libraries/stdlib/src/generated/_Streams.kt @@ -119,6 +119,17 @@ public fun Iterable.stream(): Stream { } } +/** + * Returns a stream from the given collection + */ +public fun Map.stream(): Stream> { + return object : Stream> { + override fun iterator(): Iterator> { + return this@stream.iterator() + } + } +} + /** * Returns a stream from the given collection */ diff --git a/libraries/stdlib/test/collections/MapTest.kt b/libraries/stdlib/test/collections/MapTest.kt index 9eb6e473711..6dbe14f26bf 100644 --- a/libraries/stdlib/test/collections/MapTest.kt +++ b/libraries/stdlib/test/collections/MapTest.kt @@ -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() diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Stream.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Stream.kt index 77ff1e3e1d7..e6b1c7abb85 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Stream.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Stream.kt @@ -6,6 +6,7 @@ fun streams(): List { val templates = arrayListOf() templates add f("stream()") { + include(Maps) doc { "Returns a stream from the given collection" } returns("Stream") body {