kotlin.to

to

infix fun <A, B> A.to(that: B): Pair<A, B>

Creates a tuple of type Pair from this and that.

This can be useful for creating Map literals with less noise, for example:

import kotlin.test.*
import java.util.*
import kotlin.comparisons.*

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–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/to.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部