Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions libraries/stdlib/samples/test/samples/collections/arrays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,54 @@ class Arrays {

}

class Constructors {
@Sample
fun doubleArrayOf() {
val doubleArray = doubleArrayOf(1.0, 2.5, 3.14)
assertPrints(doubleArray.contentToString(), "[1.0, 2.5, 3.14]")
}

@Sample
fun floatArrayOf() {
val floatArray = floatArrayOf(1.0f, 2.5f, 3.14f)
assertPrints(floatArray.contentToString(), "[1.0, 2.5, 3.14]")
}

@Sample
fun longArrayOf() {
val longArray = longArrayOf(1L, 2L, 3L)
assertPrints(longArray.contentToString(), "[1, 2, 3]")
}

@Sample
fun intArrayOf() {
val intArray = intArrayOf(1, 2, 3)
assertPrints(intArray.contentToString(), "[1, 2, 3]")
}

@Sample
fun charArrayOf() {
val chars = charArrayOf('a', 'b', 'c')
assertPrints(chars.contentToString(), "[a, b, c]")
}

@Sample
fun shortArrayOf() {
val shortArray = shortArrayOf(1, 2, 3)
assertPrints(shortArray.contentToString(), "[1, 2, 3]")
}

@Sample
fun byteArrayOf() {
val byteArray = byteArrayOf(1, 2, 3)
assertPrints(byteArray.contentToString(), "[1, 2, 3]")
}

@Sample
fun booleanArrayOf() {
val booleanArray = booleanArrayOf(true, false, true)
assertPrints(booleanArray.contentToString(), "[true, false, true]")
}
}

}
16 changes: 16 additions & 0 deletions libraries/stdlib/src/kotlin/Library.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,57 @@ public expect inline fun <reified T> arrayOf(vararg elements: T): Array<T>

/**
* Returns an array containing the specified [Double] numbers.
*
* @sample samples.collections.Arrays.Constructors.doubleArrayOf
*/
public expect fun doubleArrayOf(vararg elements: Double): DoubleArray

/**
* Returns an array containing the specified [Float] numbers.
*
* @sample samples.collections.Arrays.Constructors.floatArrayOf
*/
public expect fun floatArrayOf(vararg elements: Float): FloatArray

/**
* Returns an array containing the specified [Long] numbers.
*
* @sample samples.collections.Arrays.Constructors.longArrayOf
*/
public expect fun longArrayOf(vararg elements: Long): LongArray

/**
* Returns an array containing the specified [Int] numbers.
*
* @sample samples.collections.Arrays.Constructors.intArrayOf
*/
public expect fun intArrayOf(vararg elements: Int): IntArray

/**
* Returns an array containing the specified characters.
*
* @sample samples.collections.Arrays.Constructors.charArrayOf
*/
public expect fun charArrayOf(vararg elements: Char): CharArray

/**
* Returns an array containing the specified [Short] numbers.
*
* @sample samples.collections.Arrays.Constructors.shortArrayOf
*/
public expect fun shortArrayOf(vararg elements: Short): ShortArray

/**
* Returns an array containing the specified [Byte] numbers.
*
* @sample samples.collections.Arrays.Constructors.byteArrayOf
*/
public expect fun byteArrayOf(vararg elements: Byte): ByteArray

/**
* Returns an array containing the specified boolean values.
*
* @sample samples.collections.Arrays.Constructors.booleanArrayOf
*/
public expect fun booleanArrayOf(vararg elements: Boolean): BooleanArray

Expand Down