Add documentation on how merging works for toMap() for Iterables, Arrays and Sequences

This commit is contained in:
Bernhard Posselt
2018-12-10 22:57:52 +01:00
committed by ilya-g
parent 48bd99730d
commit 300f68e0d8
@@ -488,6 +488,7 @@ public inline fun <K, V> Map<out K, V>.filterNot(predicate: (Map.Entry<K, V>) ->
* Returns a new map containing all key-value pairs from the given collection of pairs.
*
* The returned map preserves the entry iteration order of the original collection.
* Duplicate keys are ignored except for the last one.
*/
public fun <K, V> Iterable<Pair<K, V>>.toMap(): Map<K, V> {
if (this is Collection) {
@@ -510,6 +511,7 @@ public fun <K, V, M : MutableMap<in K, in V>> Iterable<Pair<K, V>>.toMap(destina
* Returns a new map containing all key-value pairs from the given array of pairs.
*
* The returned map preserves the entry iteration order of the original array.
* Duplicate keys are ignored except for the last one.
*/
public fun <K, V> Array<out Pair<K, V>>.toMap(): Map<K, V> = when (size) {
0 -> emptyMap()
@@ -527,6 +529,7 @@ public fun <K, V, M : MutableMap<in K, in V>> Array<out Pair<K, V>>.toMap(destin
* Returns a new map containing all key-value pairs from the given sequence of pairs.
*
* The returned map preserves the entry iteration order of the original sequence.
* Duplicate keys are ignored except for the last one.
*/
public fun <K, V> Sequence<Pair<K, V>>.toMap(): Map<K, V> = toMap(LinkedHashMap<K, V>()).optimizeReadOnlyMap()