Move array constructors to builtins module back to kotlin package.
This commit is contained in:
@@ -2,6 +2,27 @@ package kotlin
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Returns an array with the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The `init` function returns an array element given its index.
|
||||
*/
|
||||
// TODO: @library("arrayFromFun")
|
||||
public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
||||
val result = arrayOfNulls<T>(size)
|
||||
|
||||
for (i in 0..size - 1) {
|
||||
result[i] = init(i)
|
||||
}
|
||||
|
||||
return result as Array<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty array of the specified type [T].
|
||||
*/
|
||||
public inline fun <reified T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
|
||||
|
||||
|
||||
@library
|
||||
public fun <T> arrayOf(vararg elements: T): Array<T> = noImpl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user