Rename toMap { selector } to toMapBy.
#KT-6657
This commit is contained in:
@@ -894,17 +894,9 @@ public fun <T> Iterable<T>.toList(): List<T> {
|
||||
return this.toArrayList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Map containing the values from the given collection indexed by [selector].
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
@Deprecated("Use toMapBy instead.", ReplaceWith("toMapBy(selector)"))
|
||||
public inline fun <T, K> Iterable<T>.toMap(selector: (T) -> K): Map<K, T> {
|
||||
val capacity = (collectionSizeOrDefault(10)/.75f) + 1
|
||||
val result = LinkedHashMap<K, T>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), element)
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -920,6 +912,19 @@ public inline fun <T, K, V> Iterable<T>.toMap(selector: (T) -> K, transform: (T)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Map containing the values from the given collection indexed by [selector].
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <T, K> Iterable<T>.toMapBy(selector: (T) -> K): Map<K, T> {
|
||||
val capacity = (collectionSizeOrDefault(10)/.75f) + 1
|
||||
val result = LinkedHashMap<K, T>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), element)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set] of all elements.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user