to
Требования к платформе и версии: JVM (1.0), JS (1.0), Native (1.0)
infix fun <A, B> A.to(that: B): Pair<A, B>
Создаёт кортеж типа Pair из этого и that.
Это может быть полезно для создания литералов Map с меньшим количеством шума, например:
import kotlin.test.*
import java.util.*
fun main(args: Array<String>) {
//sampleStart
val map = mapOf(1 to "x", 2 to "y", -1 to "zz")
println(map) // {1=x, 2=y, -1=zz}
//sampleEnd
}
© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/to.html