Move array constructors to builtins module back to kotlin package.

This commit is contained in:
Ilya Gorbunov
2015-12-04 23:46:26 +03:00
parent 5aff07561d
commit f509937037
4 changed files with 116 additions and 0 deletions
+21
View File
@@ -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