diff --git a/libraries/stdlib/src/generated/_Snapshots.kt b/libraries/stdlib/src/generated/_Snapshots.kt index 8b88e8c5833..8692019f98d 100644 --- a/libraries/stdlib/src/generated/_Snapshots.kt +++ b/libraries/stdlib/src/generated/_Snapshots.kt @@ -507,6 +507,138 @@ public fun String.toList(): List { return toCollection(ArrayList()) } +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun Array.toMap(selector: (T) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun BooleanArray.toMap(selector: (Boolean) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun ByteArray.toMap(selector: (Byte) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun CharArray.toMap(selector: (Char) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun DoubleArray.toMap(selector: (Double) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun FloatArray.toMap(selector: (Float) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun IntArray.toMap(selector: (Int) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun LongArray.toMap(selector: (Long) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun ShortArray.toMap(selector: (Short) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun Iterable.toMap(selector: (T) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun Stream.toMap(selector: (T) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + +/** + * Returns Map containing all the values from the given collection indexed by *selector* + */ +public inline fun String.toMap(selector: (Char) -> K): Map { + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result +} + /** * Returns a Set of all elements */ diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt index 40028f43a50..0432bdbd2b7 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt @@ -106,5 +106,25 @@ fun snapshots(): List { body { "return toCollection(LinkedList())" } } + templates add f("toMap(selector: (T) -> K)") { + inline(true) + typeParam("K") + doc { + """ + Returns Map containing all the values from the given collection indexed by *selector* + """ + } + returns("Map") + body { + """ + val result = HashMap() + for (element in this) { + result.put(selector(element), element) + } + return result + """ + } + } + return templates } \ No newline at end of file