associateWithTo所在位置是kotlin.text.associateWithTo,其相关用法介绍如下。

用法:

inline fun <V, M : MutableMap<in Char, in V>> CharSequence.associateWithTo(
    destination: M, 
    valueSelector: (Char) -> V
): M

使用给定字符序列的每个字符的键值对填充并返回 destination 可变映射,其中键是字符本身,值由应用于该键的 valueSelector 函数提供。

如果任何两个字符相等,则最后一个字符将覆盖映射中的前一个值。

例子:

import java.util.Locale
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val string = "bonne journée"
// associate each character with its code
val result = mutableMapOf<Char, Int>()
string.associateWithTo(result) { char -> char.code }
// notice each letter occurs only once
println(result) // {b=98, o=111, n=110, e=101,  =32, j=106, u=117, r=114, é=233}
//sampleEnd
}

输出:

{b=98, o=111, n=110, e=101,  =32, j=106, u=117, r=114, é=233}