Rename toMap with selector and transform to toMapBy
This commit is contained in:
@@ -5891,117 +5891,81 @@ public inline fun <K> ShortArray.toMap(selector: (Short) -> K): Map<K, Short> {
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <T, K, V> Array<out T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> BooleanArray.toMap(selector: (Boolean) -> K, transform: (Boolean) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> ByteArray.toMap(selector: (Byte) -> K, transform: (Byte) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> CharArray.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> DoubleArray.toMap(selector: (Double) -> K, transform: (Double) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> FloatArray.toMap(selector: (Float) -> K, transform: (Float) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> IntArray.toMap(selector: (Int) -> K, transform: (Int) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> LongArray.toMap(selector: (Long) -> K, transform: (Long) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, transform)"))
|
||||
public inline fun <K, V> ShortArray.toMap(selector: (Short) -> K, transform: (Short) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6256,6 +6220,123 @@ public inline fun <K> ShortArray.toMapBy(selector: (Short) -> K): Map<K, Short>
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* 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, V> Array<out T>.toMapBy(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> BooleanArray.toMapBy(selector: (Boolean) -> K, transform: (Boolean) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> ByteArray.toMapBy(selector: (Byte) -> K, transform: (Byte) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> CharArray.toMapBy(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> DoubleArray.toMapBy(selector: (Double) -> K, transform: (Double) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> FloatArray.toMapBy(selector: (Float) -> K, transform: (Float) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> IntArray.toMapBy(selector: (Int) -> K, transform: (Int) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> LongArray.toMapBy(selector: (Long) -> K, transform: (Long) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
|
||||
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> ShortArray.toMapBy(selector: (Short) -> K, transform: (Short) -> V): Map<K, V> {
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set] of all elements.
|
||||
*/
|
||||
|
||||
@@ -1073,13 +1073,9 @@ public inline fun <T, K> Iterable<T>.toMap(selector: (T) -> K): Map<K, T> {
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given collection.
|
||||
* 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, transform)"))
|
||||
public inline fun <T, K, V> Iterable<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
|
||||
val capacity = (collectionSizeOrDefault(10)/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1110,6 +1106,19 @@ public inline fun <T, K> Iterable<T>.toMapBy(selector: (T) -> K): Map<K, T> {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given collection.
|
||||
* 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, V> Iterable<T>.toMapBy(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
|
||||
val capacity = (collectionSizeOrDefault(10)/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set] of all elements.
|
||||
*/
|
||||
|
||||
@@ -531,12 +531,9 @@ public inline fun <T, K> Sequence<T>.toMap(selector: (T) -> K): Map<K, T> {
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given sequence.
|
||||
* 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, transform)"))
|
||||
public inline fun <T, K, V> Sequence<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
|
||||
val result = LinkedHashMap<K, V>()
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -565,6 +562,18 @@ public inline fun <T, K> Sequence<T>.toMapBy(selector: (T) -> K): Map<K, T> {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given sequence.
|
||||
* 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, V> Sequence<T>.toMapBy(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
|
||||
val result = LinkedHashMap<K, V>()
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set] of all elements.
|
||||
*/
|
||||
|
||||
@@ -819,13 +819,9 @@ public inline fun <K> String.toMap(selector: (Char) -> K): Map<K, Char> {
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to characters of the given char sequence.
|
||||
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
@Deprecated("Use toMapBy instead.", ReplaceWith("toMapBy(selector, transform)"))
|
||||
public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -834,12 +830,7 @@ public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (C
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <K, V> String.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
return toMapBy(selector, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -885,6 +876,19 @@ public inline fun <K> String.toMapBy(selector: (Char) -> K): Map<K, Char> {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to characters of the given char sequence.
|
||||
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> CharSequence.toMapBy(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set] of all characters.
|
||||
*/
|
||||
|
||||
@@ -241,6 +241,24 @@ fun snapshots(): List<GenericFunction> {
|
||||
}
|
||||
|
||||
templates add f("toMap(selector: (T) -> K, transform: (T) -> V)") {
|
||||
inline(true)
|
||||
include(CharSequences)
|
||||
typeParam("K")
|
||||
typeParam("V")
|
||||
doc { f ->
|
||||
"""
|
||||
Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to ${f.element.pluralize()} of the given ${f.collection}.
|
||||
If any two ${f.element.pluralize()} would have the same key returned by [selector] the last one gets added to the map.
|
||||
"""
|
||||
}
|
||||
returns("Map<K, V>")
|
||||
deprecate(Deprecation("Use toMapBy instead.", "toMapBy(selector, transform)"))
|
||||
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(Strings) { "return toMapBy(selector, transform)"}
|
||||
}
|
||||
|
||||
templates add f("toMapBy(selector: (T) -> K, transform: (T) -> V)") {
|
||||
inline(true)
|
||||
typeParam("K")
|
||||
typeParam("V")
|
||||
@@ -276,8 +294,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
return result
|
||||
"""
|
||||
}
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
body(CharSequences) {
|
||||
"""
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
|
||||
Reference in New Issue
Block a user