Rename toMap { selector } to toMapBy.

#KT-6657
This commit is contained in:
Ilya Gorbunov
2015-10-08 00:39:47 +03:00
parent fd7b670414
commit e09c0ae2ff
6 changed files with 191 additions and 121 deletions
+15 -10
View File
@@ -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.
*/