From b5145f1a87c2835e0bb3c2b1284f611b3d532d97 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 26 Sep 2012 09:04:08 +0100 Subject: [PATCH] allow mapValues() to be used on a Map not just a MutableMap --- libraries/stdlib/src/kotlin/Maps.kt | 6 +++--- libraries/stdlib/src/kotlin/MapsJVM.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/stdlib/src/kotlin/Maps.kt b/libraries/stdlib/src/kotlin/Maps.kt index 3632653de1b..4e32aa9524c 100644 --- a/libraries/stdlib/src/kotlin/Maps.kt +++ b/libraries/stdlib/src/kotlin/Maps.kt @@ -93,7 +93,7 @@ public inline fun > Map.mapTo(result: C, /** * Populates the given *result* [[Map]] with the value returned by applying the *transform* function on each [[Map.Entry]] in this [[Map]] */ -public inline fun > MutableMap.mapValuesTo(result: C, transform : (Map.Entry) -> R) : C { +public inline fun > Map.mapValuesTo(result: C, transform : (Map.Entry) -> R) : C { for (e in this) { val newValue = transform(e) result.put(e.key, newValue) @@ -102,7 +102,7 @@ public inline fun > MutableMap.mapValuesTo(result: } /** - * Puts all the entries into the map with the first value in the tuple being the key and the second the value + * Puts all the entries into this [[MutableMap]] with the first value in the pair being the key and the second the value */ public inline fun MutableMap.putAll(vararg values: Pair): Unit { for (v in values) { @@ -111,7 +111,7 @@ public inline fun MutableMap.putAll(vararg values: Pair): Unit } /** - * Copies the entries in this [[Map]] to the given *map* + * Copies the entries in this [[Map]] to the given mutable *map* */ public inline fun Map.toMap(map: MutableMap): Map { map.putAll(this) diff --git a/libraries/stdlib/src/kotlin/MapsJVM.kt b/libraries/stdlib/src/kotlin/MapsJVM.kt index be615a9c814..9bd11df7220 100644 --- a/libraries/stdlib/src/kotlin/MapsJVM.kt +++ b/libraries/stdlib/src/kotlin/MapsJVM.kt @@ -57,7 +57,7 @@ public inline fun Map.map(transform: (Map.Entry) -> R) : List< * * @includeFunctionBody ../../test/MapTest.kt mapValues */ -public inline fun MutableMap.mapValues(transform : (Map.Entry) -> R): Map { +public inline fun Map.mapValues(transform : (Map.Entry) -> R): Map { return mapValuesTo(java.util.HashMap(this.size), transform) }