KT-20357 Add sample code for Pair/Triple.toList
This commit is contained in:
@@ -20,4 +20,27 @@ class Tuples {
|
||||
assertPrints(c, "[null]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun pairToList() {
|
||||
val mixedList: List<Any> = Pair(1, "a").toList()
|
||||
assertPrints(mixedList, "[1, a]")
|
||||
assertTrue(mixedList[0] is Int)
|
||||
assertTrue(mixedList[1] is String)
|
||||
|
||||
val intList: List<Int> = Pair(0, 1).toList()
|
||||
assertPrints(intList, "[0, 1]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun tripleToList() {
|
||||
val mixedList: List<Any> = Triple(1, "a", 0.5).toList()
|
||||
assertPrints(mixedList, "[1, a, 0.5]")
|
||||
assertTrue(mixedList[0] is Int)
|
||||
assertTrue(mixedList[1] is String)
|
||||
assertTrue(mixedList[2] is Double)
|
||||
|
||||
val intList: List<Int> = Triple(0, 1, 2).toList()
|
||||
assertPrints(intList, "[0, 1, 2]")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,6 +44,7 @@ public infix fun <A, B> A.to(that: B): Pair<A, B> = Pair(this, that)
|
||||
|
||||
/**
|
||||
* Converts this pair into a list.
|
||||
* @sample samples.misc.Tuples.pairToList
|
||||
*/
|
||||
public fun <T> Pair<T, T>.toList(): List<T> = listOf(first, second)
|
||||
|
||||
@@ -76,5 +77,6 @@ public data class Triple<out A, out B, out C>(
|
||||
|
||||
/**
|
||||
* Converts this triple into a list.
|
||||
* @sample samples.misc.Tuples.tripleToList
|
||||
*/
|
||||
public fun <T> Triple<T, T, T>.toList(): List<T> = listOf(first, second, third)
|
||||
|
||||
Reference in New Issue
Block a user