Provide MutableList.fill for JS, annotate new API with @SinceKotlin
#KT-8823 #KT-9010
This commit is contained in:
@@ -79,6 +79,18 @@ public fun <T> setOf(element: T): Set<T> = hashSetOf(element)
|
||||
*/
|
||||
public fun <K, V> mapOf(pair: Pair<K, V>): Map<K, V> = hashMapOf(pair)
|
||||
|
||||
/**
|
||||
* Fills the list with the provided [value].
|
||||
*
|
||||
* Each element in the list gets replaced with the [value].
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> MutableList<T>.fill(value: T) {
|
||||
for (index in 0..lastIndex) {
|
||||
this[index] = value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts elements in the list in-place according to their natural sort order.
|
||||
*/
|
||||
|
||||
@@ -149,6 +149,8 @@ expect inline fun <reified T> Array<out T>?.orEmpty(): Array<out T>
|
||||
|
||||
expect inline fun <reified T> Collection<T>.toTypedArray(): Array<T>
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
expect fun <T> MutableList<T>.fill(value: T): Unit
|
||||
expect fun <T : Comparable<T>> MutableList<T>.sort(): Unit
|
||||
expect fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit
|
||||
|
||||
|
||||
@@ -291,6 +291,7 @@ public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
@kotlin.internal.InlineOnly
|
||||
@SinceKotlin("1.2")
|
||||
public inline fun <T> MutableList<T>.fill(value: T) {
|
||||
java.util.Collections.fill(this, value)
|
||||
}
|
||||
@@ -301,6 +302,7 @@ public inline fun <T> MutableList<T>.fill(value: T) {
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
@kotlin.internal.InlineOnly
|
||||
@SinceKotlin("1.2")
|
||||
public inline fun <T> MutableList<T>.shuffle() {
|
||||
java.util.Collections.shuffle(this)
|
||||
}
|
||||
@@ -310,6 +312,7 @@ public inline fun <T> MutableList<T>.shuffle() {
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
@kotlin.internal.InlineOnly
|
||||
@SinceKotlin("1.2")
|
||||
public inline fun <T> MutableList<T>.shuffle(random: java.util.Random) {
|
||||
java.util.Collections.shuffle(this, random)
|
||||
}
|
||||
@@ -318,6 +321,7 @@ public inline fun <T> MutableList<T>.shuffle(random: java.util.Random) {
|
||||
* Returns a new list with the elements of this list randomly shuffled.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> Iterable<T>.shuffled(): List<T> = toMutableList().apply { shuffle() }
|
||||
|
||||
/**
|
||||
@@ -325,4 +329,5 @@ public fun <T> Iterable<T>.shuffled(): List<T> = toMutableList().apply { shuffle
|
||||
* using the specified [random] instance as the source of randomness.
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> Iterable<T>.shuffled(random: java.util.Random): List<T> = toMutableList().apply { shuffle(random) }
|
||||
|
||||
@@ -95,7 +95,6 @@ class MutableCollectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmVersion
|
||||
@Test fun listFill() {
|
||||
val list = MutableList(3) { it }
|
||||
list.fill(42)
|
||||
|
||||
Reference in New Issue
Block a user