Move array constructors to builtins module back to kotlin package.
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kotlin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
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>
|
||||||
|
|
||||||
|
|
||||||
|
// Array "constructor"
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified elements.
|
||||||
|
*/
|
||||||
|
public inline fun <reified T> arrayOf(vararg elements: T) : Array<T> = elements as Array<T>
|
||||||
|
|
||||||
|
// "constructors" for primitive types array
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified [Double] numbers.
|
||||||
|
*/
|
||||||
|
public fun doubleArrayOf(vararg elements: Double) : DoubleArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified [Float] numbers.
|
||||||
|
*/
|
||||||
|
public fun floatArrayOf(vararg elements: Float) : FloatArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified [Long] numbers.
|
||||||
|
*/
|
||||||
|
public fun longArrayOf(vararg elements: Long) : LongArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified [Int] numbers.
|
||||||
|
*/
|
||||||
|
public fun intArrayOf(vararg elements: Int) : IntArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified characters.
|
||||||
|
*/
|
||||||
|
public fun charArrayOf(vararg elements: Char) : CharArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified [Short] numbers.
|
||||||
|
*/
|
||||||
|
public fun shortArrayOf(vararg elements: Short) : ShortArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified [Byte] numbers.
|
||||||
|
*/
|
||||||
|
public fun byteArrayOf(vararg elements: Byte) : ByteArray = elements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing the specified boolean values.
|
||||||
|
*/
|
||||||
|
public fun booleanArrayOf(vararg elements: Boolean) : BooleanArray = elements
|
||||||
@@ -2,6 +2,27 @@ package kotlin
|
|||||||
|
|
||||||
import java.util.*
|
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
|
@library
|
||||||
public fun <T> arrayOf(vararg elements: T): Array<T> = noImpl
|
public fun <T> arrayOf(vararg elements: T): Array<T> = noImpl
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.util.*
|
|||||||
* Returns an array with the specified [size], where each element is calculated by calling the specified
|
* 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.
|
* [init] function. The `init` function returns an array element given its index.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
||||||
val result = arrayOfNulls<T>(size)
|
val result = arrayOfNulls<T>(size)
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
|||||||
/**
|
/**
|
||||||
* Returns an empty array of the specified type [T].
|
* Returns an empty array of the specified type [T].
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public inline fun <reified T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
|
public inline fun <reified T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,47 +10,56 @@ import java.nio.charset.Charset
|
|||||||
/**
|
/**
|
||||||
* Returns an array containing the specified elements.
|
* Returns an array containing the specified elements.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public inline fun <reified T> arrayOf(vararg elements: T) : Array<T> = elements as Array<T>
|
public inline fun <reified T> arrayOf(vararg elements: T) : Array<T> = elements as Array<T>
|
||||||
|
|
||||||
// "constructors" for primitive types array
|
// "constructors" for primitive types array
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified [Double] numbers.
|
* Returns an array containing the specified [Double] numbers.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun doubleArrayOf(vararg elements: Double) : DoubleArray = elements
|
public fun doubleArrayOf(vararg elements: Double) : DoubleArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified [Float] numbers.
|
* Returns an array containing the specified [Float] numbers.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun floatArrayOf(vararg elements: Float) : FloatArray = elements
|
public fun floatArrayOf(vararg elements: Float) : FloatArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified [Long] numbers.
|
* Returns an array containing the specified [Long] numbers.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun longArrayOf(vararg elements: Long) : LongArray = elements
|
public fun longArrayOf(vararg elements: Long) : LongArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified [Int] numbers.
|
* Returns an array containing the specified [Int] numbers.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun intArrayOf(vararg elements: Int) : IntArray = elements
|
public fun intArrayOf(vararg elements: Int) : IntArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified characters.
|
* Returns an array containing the specified characters.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun charArrayOf(vararg elements: Char) : CharArray = elements
|
public fun charArrayOf(vararg elements: Char) : CharArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified [Short] numbers.
|
* Returns an array containing the specified [Short] numbers.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun shortArrayOf(vararg elements: Short) : ShortArray = elements
|
public fun shortArrayOf(vararg elements: Short) : ShortArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified [Byte] numbers.
|
* Returns an array containing the specified [Byte] numbers.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun byteArrayOf(vararg elements: Byte) : ByteArray = elements
|
public fun byteArrayOf(vararg elements: Byte) : ByteArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified boolean values.
|
* Returns an array containing the specified boolean values.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||||
public fun booleanArrayOf(vararg elements: Boolean) : BooleanArray = elements
|
public fun booleanArrayOf(vararg elements: Boolean) : BooleanArray = elements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user