Map.getOrImplicitDefault is exposed public as Map.getValue
#KT-11851
This commit is contained in:
@@ -21,8 +21,9 @@ internal fun <K, V> Map<K, V>.getOrImplicitDefault(key: K): V {
|
||||
|
||||
/**
|
||||
* Returns a wrapper of this read-only map, having the implicit default value provided with the specified function [defaultValue].
|
||||
* This implicit default value is used when properties are delegated to the returned map,
|
||||
* and that map doesn't contain a value for the key specified.
|
||||
*
|
||||
* This implicit default value is used when the original map doesn't contain a value for the key specified
|
||||
* and a value is obtained with [Map.getValue] function, for example when properties are delegated to the map.
|
||||
*
|
||||
* When this map already has an implicit default value provided with a former call to [withDefault], it is being replaced by this call.
|
||||
*/
|
||||
@@ -34,8 +35,9 @@ public fun <K, V> Map<K, V>.withDefault(defaultValue: (key: K) -> V): Map<K, V>
|
||||
|
||||
/**
|
||||
* Returns a wrapper of this mutable map, having the implicit default value provided with the specified function [defaultValue].
|
||||
* This implicit default value is used when properties are delegated to the returned map,
|
||||
* and that map doesn't contain a value for the key specified.
|
||||
*
|
||||
* This implicit default value is used when the original map doesn't contain a value for the key specified
|
||||
* and a value is obtained with [Map.getValue] function, for example when properties are delegated to the map.
|
||||
*
|
||||
* When this map already has an implicit default value provided with a former call to [withDefault], it is being replaced by this call.
|
||||
*/
|
||||
|
||||
@@ -216,7 +216,17 @@ internal inline fun <K, V> Map<K, V>.getOrElseNullable(key: K, defaultValue: ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value for the given [key] or throws an exception if there is no such key in the map.
|
||||
*
|
||||
* If the map was created by [withDefault], resorts to its `defaultValue` provider function
|
||||
* instead of throwing an exception.
|
||||
*
|
||||
* @throws NoSuchElementException when the map doesn't contain a value for the specified key and
|
||||
* no implicit default value was provided for that map.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public fun <K, V> Map<K, V>.getValue(key: K): V = getOrImplicitDefault(key)
|
||||
|
||||
/**
|
||||
* Returns the value for the given key. If the key is not found in the map, calls the [defaultValue] function,
|
||||
|
||||
Reference in New Issue
Block a user