KT-20357: Add samples for associate* functions (#2798)

* KT-20357: Add samples for functions related to associate

* KT-20357: Use same fib function for both samples

* KT-20357: Use examples with duplicate keys and simplify examples with primitives

* KT-20357: Use primitive samples for all arrays

* KT-20357: Use String splitting example to better illustrate the use for associate over associateBy with a valueSelector
This commit is contained in:
Dat Trieu
2019-11-29 14:54:02 +01:00
committed by ilya-g
parent d2e5432b2d
commit f334ad2ffc
8 changed files with 420 additions and 0 deletions
@@ -7145,6 +7145,8 @@ public expect fun CharArray.toTypedArray(): Array<Char>
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <T, K, V> Array<out T>.associate(transform: (T) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7158,6 +7160,8 @@ public inline fun <T, K, V> Array<out T>.associate(transform: (T) -> Pair<K, V>)
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> ByteArray.associate(transform: (Byte) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7171,6 +7175,8 @@ public inline fun <K, V> ByteArray.associate(transform: (Byte) -> Pair<K, V>): M
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> ShortArray.associate(transform: (Short) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7184,6 +7190,8 @@ public inline fun <K, V> ShortArray.associate(transform: (Short) -> Pair<K, V>):
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> IntArray.associate(transform: (Int) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7197,6 +7205,8 @@ public inline fun <K, V> IntArray.associate(transform: (Int) -> Pair<K, V>): Map
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> LongArray.associate(transform: (Long) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7210,6 +7220,8 @@ public inline fun <K, V> LongArray.associate(transform: (Long) -> Pair<K, V>): M
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> FloatArray.associate(transform: (Float) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7223,6 +7235,8 @@ public inline fun <K, V> FloatArray.associate(transform: (Float) -> Pair<K, V>):
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> DoubleArray.associate(transform: (Double) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7236,6 +7250,8 @@ public inline fun <K, V> DoubleArray.associate(transform: (Double) -> Pair<K, V>
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> BooleanArray.associate(transform: (Boolean) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7249,6 +7265,8 @@ public inline fun <K, V> BooleanArray.associate(transform: (Boolean) -> Pair<K,
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitives
*/
public inline fun <K, V> CharArray.associate(transform: (Char) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7262,6 +7280,8 @@ public inline fun <K, V> CharArray.associate(transform: (Char) -> Pair<K, V>): M
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <T, K> Array<out T>.associateBy(keySelector: (T) -> K): Map<K, T> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7275,6 +7295,8 @@ public inline fun <T, K> Array<out T>.associateBy(keySelector: (T) -> K): Map<K,
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> ByteArray.associateBy(keySelector: (Byte) -> K): Map<K, Byte> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7288,6 +7310,8 @@ public inline fun <K> ByteArray.associateBy(keySelector: (Byte) -> K): Map<K, By
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> ShortArray.associateBy(keySelector: (Short) -> K): Map<K, Short> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7301,6 +7325,8 @@ public inline fun <K> ShortArray.associateBy(keySelector: (Short) -> K): Map<K,
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> IntArray.associateBy(keySelector: (Int) -> K): Map<K, Int> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7314,6 +7340,8 @@ public inline fun <K> IntArray.associateBy(keySelector: (Int) -> K): Map<K, Int>
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> LongArray.associateBy(keySelector: (Long) -> K): Map<K, Long> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7327,6 +7355,8 @@ public inline fun <K> LongArray.associateBy(keySelector: (Long) -> K): Map<K, Lo
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> FloatArray.associateBy(keySelector: (Float) -> K): Map<K, Float> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7340,6 +7370,8 @@ public inline fun <K> FloatArray.associateBy(keySelector: (Float) -> K): Map<K,
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> DoubleArray.associateBy(keySelector: (Double) -> K): Map<K, Double> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7353,6 +7385,8 @@ public inline fun <K> DoubleArray.associateBy(keySelector: (Double) -> K): Map<K
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> BooleanArray.associateBy(keySelector: (Boolean) -> K): Map<K, Boolean> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7366,6 +7400,8 @@ public inline fun <K> BooleanArray.associateBy(keySelector: (Boolean) -> K): Map
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesBy
*/
public inline fun <K> CharArray.associateBy(keySelector: (Char) -> K): Map<K, Char> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7378,6 +7414,8 @@ public inline fun <K> CharArray.associateBy(keySelector: (Char) -> K): Map<K, Ch
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <T, K, V> Array<out T>.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7390,6 +7428,8 @@ public inline fun <T, K, V> Array<out T>.associateBy(keySelector: (T) -> K, valu
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> ByteArray.associateBy(keySelector: (Byte) -> K, valueTransform: (Byte) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7402,6 +7442,8 @@ public inline fun <K, V> ByteArray.associateBy(keySelector: (Byte) -> K, valueTr
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> ShortArray.associateBy(keySelector: (Short) -> K, valueTransform: (Short) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7414,6 +7456,8 @@ public inline fun <K, V> ShortArray.associateBy(keySelector: (Short) -> K, value
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> IntArray.associateBy(keySelector: (Int) -> K, valueTransform: (Int) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7426,6 +7470,8 @@ public inline fun <K, V> IntArray.associateBy(keySelector: (Int) -> K, valueTran
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> LongArray.associateBy(keySelector: (Long) -> K, valueTransform: (Long) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7438,6 +7484,8 @@ public inline fun <K, V> LongArray.associateBy(keySelector: (Long) -> K, valueTr
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> FloatArray.associateBy(keySelector: (Float) -> K, valueTransform: (Float) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7450,6 +7498,8 @@ public inline fun <K, V> FloatArray.associateBy(keySelector: (Float) -> K, value
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> DoubleArray.associateBy(keySelector: (Double) -> K, valueTransform: (Double) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7462,6 +7512,8 @@ public inline fun <K, V> DoubleArray.associateBy(keySelector: (Double) -> K, val
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> BooleanArray.associateBy(keySelector: (Boolean) -> K, valueTransform: (Boolean) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7474,6 +7526,8 @@ public inline fun <K, V> BooleanArray.associateBy(keySelector: (Boolean) -> K, v
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original array.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByWithValueTransform
*/
public inline fun <K, V> CharArray.associateBy(keySelector: (Char) -> K, valueTransform: (Char) -> V): Map<K, V> {
val capacity = mapCapacity(size).coerceAtLeast(16)
@@ -7486,6 +7540,8 @@ public inline fun <K, V> CharArray.associateBy(keySelector: (Char) -> K, valueTr
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <T, K, M : MutableMap<in K, in T>> Array<out T>.associateByTo(destination: M, keySelector: (T) -> K): M {
for (element in this) {
@@ -7500,6 +7556,8 @@ public inline fun <T, K, M : MutableMap<in K, in T>> Array<out T>.associateByTo(
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Byte>> ByteArray.associateByTo(destination: M, keySelector: (Byte) -> K): M {
for (element in this) {
@@ -7514,6 +7572,8 @@ public inline fun <K, M : MutableMap<in K, in Byte>> ByteArray.associateByTo(des
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Short>> ShortArray.associateByTo(destination: M, keySelector: (Short) -> K): M {
for (element in this) {
@@ -7528,6 +7588,8 @@ public inline fun <K, M : MutableMap<in K, in Short>> ShortArray.associateByTo(d
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Int>> IntArray.associateByTo(destination: M, keySelector: (Int) -> K): M {
for (element in this) {
@@ -7542,6 +7604,8 @@ public inline fun <K, M : MutableMap<in K, in Int>> IntArray.associateByTo(desti
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Long>> LongArray.associateByTo(destination: M, keySelector: (Long) -> K): M {
for (element in this) {
@@ -7556,6 +7620,8 @@ public inline fun <K, M : MutableMap<in K, in Long>> LongArray.associateByTo(des
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Float>> FloatArray.associateByTo(destination: M, keySelector: (Float) -> K): M {
for (element in this) {
@@ -7570,6 +7636,8 @@ public inline fun <K, M : MutableMap<in K, in Float>> FloatArray.associateByTo(d
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Double>> DoubleArray.associateByTo(destination: M, keySelector: (Double) -> K): M {
for (element in this) {
@@ -7584,6 +7652,8 @@ public inline fun <K, M : MutableMap<in K, in Double>> DoubleArray.associateByTo
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Boolean>> BooleanArray.associateByTo(destination: M, keySelector: (Boolean) -> K): M {
for (element in this) {
@@ -7598,6 +7668,8 @@ public inline fun <K, M : MutableMap<in K, in Boolean>> BooleanArray.associateBy
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByTo
*/
public inline fun <K, M : MutableMap<in K, in Char>> CharArray.associateByTo(destination: M, keySelector: (Char) -> K): M {
for (element in this) {
@@ -7612,6 +7684,8 @@ public inline fun <K, M : MutableMap<in K, in Char>> CharArray.associateByTo(des
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <T, K, V, M : MutableMap<in K, in V>> Array<out T>.associateByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {
for (element in this) {
@@ -7626,6 +7700,8 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Array<out T>.associateBy
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> ByteArray.associateByTo(destination: M, keySelector: (Byte) -> K, valueTransform: (Byte) -> V): M {
for (element in this) {
@@ -7640,6 +7716,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> ByteArray.associateByTo(des
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> ShortArray.associateByTo(destination: M, keySelector: (Short) -> K, valueTransform: (Short) -> V): M {
for (element in this) {
@@ -7654,6 +7732,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> ShortArray.associateByTo(de
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> IntArray.associateByTo(destination: M, keySelector: (Int) -> K, valueTransform: (Int) -> V): M {
for (element in this) {
@@ -7668,6 +7748,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> IntArray.associateByTo(dest
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> LongArray.associateByTo(destination: M, keySelector: (Long) -> K, valueTransform: (Long) -> V): M {
for (element in this) {
@@ -7682,6 +7764,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> LongArray.associateByTo(des
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> FloatArray.associateByTo(destination: M, keySelector: (Float) -> K, valueTransform: (Float) -> V): M {
for (element in this) {
@@ -7696,6 +7780,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> FloatArray.associateByTo(de
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> DoubleArray.associateByTo(destination: M, keySelector: (Double) -> K, valueTransform: (Double) -> V): M {
for (element in this) {
@@ -7710,6 +7796,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> DoubleArray.associateByTo(d
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> BooleanArray.associateByTo(destination: M, keySelector: (Boolean) -> K, valueTransform: (Boolean) -> V): M {
for (element in this) {
@@ -7724,6 +7812,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> BooleanArray.associateByTo(
* and value is provided by the [valueTransform] function applied to elements of the given array.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> CharArray.associateByTo(destination: M, keySelector: (Char) -> K, valueTransform: (Char) -> V): M {
for (element in this) {
@@ -7737,6 +7827,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> CharArray.associateByTo(des
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <T, K, V, M : MutableMap<in K, in V>> Array<out T>.associateTo(destination: M, transform: (T) -> Pair<K, V>): M {
for (element in this) {
@@ -7750,6 +7842,8 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Array<out T>.associateTo
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> ByteArray.associateTo(destination: M, transform: (Byte) -> Pair<K, V>): M {
for (element in this) {
@@ -7763,6 +7857,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> ByteArray.associateTo(desti
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> ShortArray.associateTo(destination: M, transform: (Short) -> Pair<K, V>): M {
for (element in this) {
@@ -7776,6 +7872,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> ShortArray.associateTo(dest
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> IntArray.associateTo(destination: M, transform: (Int) -> Pair<K, V>): M {
for (element in this) {
@@ -7789,6 +7887,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> IntArray.associateTo(destin
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> LongArray.associateTo(destination: M, transform: (Long) -> Pair<K, V>): M {
for (element in this) {
@@ -7802,6 +7902,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> LongArray.associateTo(desti
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> FloatArray.associateTo(destination: M, transform: (Float) -> Pair<K, V>): M {
for (element in this) {
@@ -7815,6 +7917,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> FloatArray.associateTo(dest
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> DoubleArray.associateTo(destination: M, transform: (Double) -> Pair<K, V>): M {
for (element in this) {
@@ -7828,6 +7932,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> DoubleArray.associateTo(des
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> BooleanArray.associateTo(destination: M, transform: (Boolean) -> Pair<K, V>): M {
for (element in this) {
@@ -7841,6 +7947,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> BooleanArray.associateTo(de
* provided by [transform] function applied to each element of the given array.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Arrays.Transformations.associateArrayOfPrimitivesTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> CharArray.associateTo(destination: M, transform: (Char) -> Pair<K, V>): M {
for (element in this) {
@@ -1056,6 +1056,8 @@ public fun Collection<Short>.toShortArray(): ShortArray {
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original collection.
*
* @sample samples.collections.Collections.Transformations.associate
*/
public inline fun <T, K, V> Iterable<T>.associate(transform: (T) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16)
@@ -1069,6 +1071,8 @@ public inline fun <T, K, V> Iterable<T>.associate(transform: (T) -> Pair<K, V>):
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original collection.
*
* @sample samples.collections.Collections.Transformations.associateBy
*/
public inline fun <T, K> Iterable<T>.associateBy(keySelector: (T) -> K): Map<K, T> {
val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16)
@@ -1081,6 +1085,8 @@ public inline fun <T, K> Iterable<T>.associateBy(keySelector: (T) -> K): Map<K,
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original collection.
*
* @sample samples.collections.Collections.Transformations.associateByWithValueTransform
*/
public inline fun <T, K, V> Iterable<T>.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, V> {
val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16)
@@ -1093,6 +1099,8 @@ public inline fun <T, K, V> Iterable<T>.associateBy(keySelector: (T) -> K, value
* and value is the element itself.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Collections.Transformations.associateByTo
*/
public inline fun <T, K, M : MutableMap<in K, in T>> Iterable<T>.associateByTo(destination: M, keySelector: (T) -> K): M {
for (element in this) {
@@ -1107,6 +1115,8 @@ public inline fun <T, K, M : MutableMap<in K, in T>> Iterable<T>.associateByTo(d
* and value is provided by the [valueTransform] function applied to elements of the given collection.
*
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.collections.Collections.Transformations.associateByToWithValueTransform
*/
public inline fun <T, K, V, M : MutableMap<in K, in V>> Iterable<T>.associateByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {
for (element in this) {
@@ -1120,6 +1130,8 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Iterable<T>.associateByT
* provided by [transform] function applied to each element of the given collection.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.collections.Collections.Transformations.associateTo
*/
public inline fun <T, K, V, M : MutableMap<in K, in V>> Iterable<T>.associateTo(destination: M, transform: (T) -> Pair<K, V>): M {
for (element in this) {
@@ -1149,6 +1161,8 @@ public inline fun <K, V> Iterable<K>.associateWith(valueSelector: (K) -> V): Map
* where key is the element itself and value is provided by the [valueSelector] function applied to that key.
*
* If any two elements are equal, the last one overwrites the former value in the map.
*
* @sample samples.collections.Collections.Transformations.associateWithTo
*/
@SinceKotlin("1.3")
public inline fun <K, V, M : MutableMap<in K, in V>> Iterable<K>.associateWithTo(destination: M, valueSelector: (K) -> V): M {
@@ -580,6 +580,8 @@ public fun <T> Sequence<T>.sortedWith(comparator: Comparator<in T>): Sequence<T>
* The returned map preserves the entry iteration order of the original sequence.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associate
*/
public inline fun <T, K, V> Sequence<T>.associate(transform: (T) -> Pair<K, V>): Map<K, V> {
return associateTo(LinkedHashMap<K, V>(), transform)
@@ -594,6 +596,8 @@ public inline fun <T, K, V> Sequence<T>.associate(transform: (T) -> Pair<K, V>):
* The returned map preserves the entry iteration order of the original sequence.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associateBy
*/
public inline fun <T, K> Sequence<T>.associateBy(keySelector: (T) -> K): Map<K, T> {
return associateByTo(LinkedHashMap<K, T>(), keySelector)
@@ -607,6 +611,8 @@ public inline fun <T, K> Sequence<T>.associateBy(keySelector: (T) -> K): Map<K,
* The returned map preserves the entry iteration order of the original sequence.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associateByWithValueTransform
*/
public inline fun <T, K, V> Sequence<T>.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, V> {
return associateByTo(LinkedHashMap<K, V>(), keySelector, valueTransform)
@@ -620,6 +626,8 @@ public inline fun <T, K, V> Sequence<T>.associateBy(keySelector: (T) -> K, value
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associateByTo
*/
public inline fun <T, K, M : MutableMap<in K, in T>> Sequence<T>.associateByTo(destination: M, keySelector: (T) -> K): M {
for (element in this) {
@@ -636,6 +644,8 @@ public inline fun <T, K, M : MutableMap<in K, in T>> Sequence<T>.associateByTo(d
* If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associateByToWithValueTransform
*/
public inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.associateByTo(destination: M, keySelector: (T) -> K, valueTransform: (T) -> V): M {
for (element in this) {
@@ -651,6 +661,8 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.associateByT
* If any of two pairs would have the same key the last one gets added to the map.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associateTo
*/
public inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.associateTo(destination: M, transform: (T) -> Pair<K, V>): M {
for (element in this) {
@@ -684,6 +696,8 @@ public inline fun <K, V> Sequence<K>.associateWith(valueSelector: (K) -> V): Map
* If any two elements are equal, the last one overwrites the former value in the map.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Transformations.associateWithTo
*/
@SinceKotlin("1.3")
public inline fun <K, V, M : MutableMap<in K, in V>> Sequence<K>.associateWithTo(destination: M, valueSelector: (K) -> V): M {
@@ -583,6 +583,8 @@ public inline fun String.reversed(): String {
* If any of two pairs would have the same key the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original char sequence.
*
* @sample samples.text.Strings.associate
*/
public inline fun <K, V> CharSequence.associate(transform: (Char) -> Pair<K, V>): Map<K, V> {
val capacity = mapCapacity(length).coerceAtLeast(16)
@@ -596,6 +598,8 @@ public inline fun <K, V> CharSequence.associate(transform: (Char) -> Pair<K, V>)
* If any two characters would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original char sequence.
*
* @sample samples.text.Strings.associateBy
*/
public inline fun <K> CharSequence.associateBy(keySelector: (Char) -> K): Map<K, Char> {
val capacity = mapCapacity(length).coerceAtLeast(16)
@@ -608,6 +612,8 @@ public inline fun <K> CharSequence.associateBy(keySelector: (Char) -> K): Map<K,
* If any two characters would have the same key returned by [keySelector] the last one gets added to the map.
*
* The returned map preserves the entry iteration order of the original char sequence.
*
* @sample samples.text.Strings.associateByWithValueTransform
*/
public inline fun <K, V> CharSequence.associateBy(keySelector: (Char) -> K, valueTransform: (Char) -> V): Map<K, V> {
val capacity = mapCapacity(length).coerceAtLeast(16)
@@ -620,6 +626,8 @@ public inline fun <K, V> CharSequence.associateBy(keySelector: (Char) -> K, valu
* and value is the character itself.
*
* If any two characters would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.text.Strings.associateByTo
*/
public inline fun <K, M : MutableMap<in K, in Char>> CharSequence.associateByTo(destination: M, keySelector: (Char) -> K): M {
for (element in this) {
@@ -634,6 +642,8 @@ public inline fun <K, M : MutableMap<in K, in Char>> CharSequence.associateByTo(
* and value is provided by the [valueTransform] function applied to characters of the given char sequence.
*
* If any two characters would have the same key returned by [keySelector] the last one gets added to the map.
*
* @sample samples.text.Strings.associateByToWithValueTransform
*/
public inline fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateByTo(destination: M, keySelector: (Char) -> K, valueTransform: (Char) -> V): M {
for (element in this) {
@@ -647,6 +657,8 @@ public inline fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateByTo(
* provided by [transform] function applied to each character of the given char sequence.
*
* If any of two pairs would have the same key the last one gets added to the map.
*
* @sample samples.text.Strings.associateTo
*/
public inline fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateTo(destination: M, transform: (Char) -> Pair<K, V>): M {
for (element in this) {
@@ -676,6 +688,8 @@ public inline fun <V> CharSequence.associateWith(valueSelector: (Char) -> V): Ma
* where key is the character itself and value is provided by the [valueSelector] function applied to that key.
*
* If any two characters are equal, the last one overwrites the former value in the map.
*
* @sample samples.text.Strings.associateWithTo
*/
@SinceKotlin("1.3")
public inline fun <V, M : MutableMap<in Char, in V>> CharSequence.associateWithTo(destination: M, valueSelector: (Char) -> V): M {