generated._Arrays.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-stdlib-common Show documentation
Show all versions of kotlin-stdlib-common Show documentation
Kotlin Common Standard Library
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("ArraysKt")
package kotlin.collections
//
// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
import kotlin.contracts.*
import kotlin.random.*
import kotlin.ranges.contains
import kotlin.ranges.reversed
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component1(): T {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component1(): Byte {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component1(): Short {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component1(): Int {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component1(): Long {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component1(): Float {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component1(): Double {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component1(): Boolean {
return get(0)
}
/**
* Returns 1st *element* from the array.
*
* If the size of this array is less than 1, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component1(): Char {
return get(0)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component2(): T {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component2(): Byte {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component2(): Short {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component2(): Int {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component2(): Long {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component2(): Float {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component2(): Double {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component2(): Boolean {
return get(1)
}
/**
* Returns 2nd *element* from the array.
*
* If the size of this array is less than 2, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component2(): Char {
return get(1)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component3(): T {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component3(): Byte {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component3(): Short {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component3(): Int {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component3(): Long {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component3(): Float {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component3(): Double {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component3(): Boolean {
return get(2)
}
/**
* Returns 3rd *element* from the array.
*
* If the size of this array is less than 3, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component3(): Char {
return get(2)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component4(): T {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component4(): Byte {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component4(): Short {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component4(): Int {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component4(): Long {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component4(): Float {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component4(): Double {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component4(): Boolean {
return get(3)
}
/**
* Returns 4th *element* from the array.
*
* If the size of this array is less than 4, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component4(): Char {
return get(3)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component5(): T {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component5(): Byte {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component5(): Short {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component5(): Int {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component5(): Long {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component5(): Float {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component5(): Double {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component5(): Boolean {
return get(4)
}
/**
* Returns 5th *element* from the array.
*
* If the size of this array is less than 5, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component5(): Char {
return get(4)
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun <@kotlin.internal.OnlyInputTypes T> Array.contains(element: T): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun ByteArray.contains(element: Byte): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun ShortArray.contains(element: Short): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun IntArray.contains(element: Int): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun LongArray.contains(element: Long): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", ReplaceWith("any { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public operator fun FloatArray.contains(element: Float): Boolean {
return any { it == element }
}
/**
* Returns `true` if [element] is found in the array.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", ReplaceWith("any { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public operator fun DoubleArray.contains(element: Double): Boolean {
return any { it == element }
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun BooleanArray.contains(element: Boolean): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun CharArray.contains(element: Char): Boolean {
return indexOf(element) >= 0
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun Array.elementAt(index: Int): T
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun ByteArray.elementAt(index: Int): Byte
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun ShortArray.elementAt(index: Int): Short
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun IntArray.elementAt(index: Int): Int
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun LongArray.elementAt(index: Int): Long
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun FloatArray.elementAt(index: Int): Float
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun DoubleArray.elementAt(index: Int): Double
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun BooleanArray.elementAt(index: Int): Boolean
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
public expect fun CharArray.elementAt(index: Int): Char
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun Array.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Byte): Byte {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Short): Short {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Int): Int {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Long): Long {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Float): Float {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Double): Double {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Boolean): Boolean {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun Array.elementAtOrNull(index: Int): T? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.elementAtOrNull(index: Int): Byte? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.elementAtOrNull(index: Int): Short? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.elementAtOrNull(index: Int): Int? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.elementAtOrNull(index: Int): Long? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.elementAtOrNull(index: Int): Float? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.elementAtOrNull(index: Int): Double? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.elementAtOrNull(index: Int): Boolean? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.elementAtOrNull(index: Int): Char? {
return this.getOrNull(index)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun Array.find(predicate: (T) -> Boolean): T? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.find(predicate: (Byte) -> Boolean): Byte? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.find(predicate: (Short) -> Boolean): Short? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.find(predicate: (Int) -> Boolean): Int? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.find(predicate: (Long) -> Boolean): Long? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.find(predicate: (Float) -> Boolean): Float? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.find(predicate: (Double) -> Boolean): Double? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.find(predicate: (Boolean) -> Boolean): Boolean? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.find(predicate: (Char) -> Boolean): Char? {
return firstOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun Array.findLast(predicate: (T) -> Boolean): T? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.findLast(predicate: (Byte) -> Boolean): Byte? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.findLast(predicate: (Short) -> Boolean): Short? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.findLast(predicate: (Int) -> Boolean): Int? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.findLast(predicate: (Long) -> Boolean): Long? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.findLast(predicate: (Float) -> Boolean): Float? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.findLast(predicate: (Double) -> Boolean): Double? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.findLast(predicate: (Boolean) -> Boolean): Boolean? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.find
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.findLast(predicate: (Char) -> Boolean): Char? {
return lastOrNull(predicate)
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun Array.first(): T {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun ByteArray.first(): Byte {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun ShortArray.first(): Short {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun IntArray.first(): Int {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun LongArray.first(): Long {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun FloatArray.first(): Float {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun DoubleArray.first(): Double {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun BooleanArray.first(): Boolean {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element.
*
* @throws NoSuchElementException if the array is empty.
*/
public fun CharArray.first(): Char {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[0]
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun Array.first(predicate: (T) -> Boolean): T {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun ShortArray.first(predicate: (Short) -> Boolean): Short {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun IntArray.first(predicate: (Int) -> Boolean): Int {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun LongArray.first(predicate: (Long) -> Boolean): Long {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun FloatArray.first(predicate: (Float) -> Boolean): Float {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
public inline fun CharArray.first(predicate: (Char) -> Boolean): Char {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first non-null value produced by [transform] function being applied to elements of this array in iteration order,
* or throws [NoSuchElementException] if no non-null value was produced.
*
* @sample samples.collections.Collections.Transformations.firstNotNullOf
*/
@SinceKotlin("1.5")
@kotlin.internal.InlineOnly
public inline fun Array.firstNotNullOf(transform: (T) -> R?): R {
return firstNotNullOfOrNull(transform) ?: throw NoSuchElementException("No element of the array was transformed to a non-null value.")
}
/**
* Returns the first non-null value produced by [transform] function being applied to elements of this array in iteration order,
* or `null` if no non-null value was produced.
*
* @sample samples.collections.Collections.Transformations.firstNotNullOf
*/
@SinceKotlin("1.5")
@kotlin.internal.InlineOnly
public inline fun Array.firstNotNullOfOrNull(transform: (T) -> R?): R? {
for (element in this) {
val result = transform(element)
if (result != null) {
return result
}
}
return null
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun Array.firstOrNull(): T? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun ByteArray.firstOrNull(): Byte? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun ShortArray.firstOrNull(): Short? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun IntArray.firstOrNull(): Int? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun LongArray.firstOrNull(): Long? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun FloatArray.firstOrNull(): Float? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun DoubleArray.firstOrNull(): Double? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun BooleanArray.firstOrNull(): Boolean? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
public fun CharArray.firstOrNull(): Char? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun Array.firstOrNull(predicate: (T) -> Boolean): T? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun ByteArray.firstOrNull(predicate: (Byte) -> Boolean): Byte? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun ShortArray.firstOrNull(predicate: (Short) -> Boolean): Short? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun IntArray.firstOrNull(predicate: (Int) -> Boolean): Int? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun LongArray.firstOrNull(predicate: (Long) -> Boolean): Long? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun FloatArray.firstOrNull(predicate: (Float) -> Boolean): Float? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun DoubleArray.firstOrNull(predicate: (Double) -> Boolean): Double? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun BooleanArray.firstOrNull(predicate: (Boolean) -> Boolean): Boolean? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
public inline fun CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? {
for (element in this) if (predicate(element)) return element
return null
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun Array.getOrElse(index: Int, defaultValue: (Int) -> T): T {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.getOrElse(index: Int, defaultValue: (Int) -> Byte): Byte {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.getOrElse(index: Int, defaultValue: (Int) -> Short): Short {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.getOrElse(index: Int, defaultValue: (Int) -> Int): Int {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.getOrElse(index: Int, defaultValue: (Int) -> Long): Long {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.getOrElse(index: Int, defaultValue: (Int) -> Float): Float {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.getOrElse(index: Int, defaultValue: (Int) -> Double): Double {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.getOrElse(index: Int, defaultValue: (Int) -> Boolean): Boolean {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.getOrElse(index: Int, defaultValue: (Int) -> Char): Char {
contract {
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
}
return if (index in indices) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun Array.getOrNull(index: Int): T? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun ByteArray.getOrNull(index: Int): Byte? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun ShortArray.getOrNull(index: Int): Short? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun IntArray.getOrNull(index: Int): Int? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun LongArray.getOrNull(index: Int): Long? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun FloatArray.getOrNull(index: Int): Float? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun DoubleArray.getOrNull(index: Int): Double? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun BooleanArray.getOrNull(index: Int): Boolean? {
return if (index in indices) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrNull
*/
public fun CharArray.getOrNull(index: Int): Char? {
return if (index in indices) get(index) else null
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun <@kotlin.internal.OnlyInputTypes T> Array.indexOf(element: T): Int {
if (element == null) {
for (index in indices) {
if (this[index] == null) {
return index
}
}
} else {
for (index in indices) {
if (element == this[index]) {
return index
}
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun ByteArray.indexOf(element: Byte): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun ShortArray.indexOf(element: Short): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun IntArray.indexOf(element: Int): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun LongArray.indexOf(element: Long): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfFirst { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun FloatArray.indexOf(element: Float): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfFirst { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun DoubleArray.indexOf(element: Double): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun BooleanArray.indexOf(element: Boolean): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
*/
public fun CharArray.indexOf(element: Char): Int {
for (index in indices) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun Array.indexOfFirst(predicate: (T) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun ByteArray.indexOfFirst(predicate: (Byte) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun ShortArray.indexOfFirst(predicate: (Short) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun IntArray.indexOfFirst(predicate: (Int) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun LongArray.indexOfFirst(predicate: (Long) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun FloatArray.indexOfFirst(predicate: (Float) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun DoubleArray.indexOfFirst(predicate: (Double) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun BooleanArray.indexOfFirst(predicate: (Boolean) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun CharArray.indexOfFirst(predicate: (Char) -> Boolean): Int {
for (index in indices) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun Array.indexOfLast(predicate: (T) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun ByteArray.indexOfLast(predicate: (Byte) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun ShortArray.indexOfLast(predicate: (Short) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun IntArray.indexOfLast(predicate: (Int) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun LongArray.indexOfLast(predicate: (Long) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun FloatArray.indexOfLast(predicate: (Float) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun DoubleArray.indexOfLast(predicate: (Double) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun BooleanArray.indexOfLast(predicate: (Boolean) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns index of the last element matching the given [predicate], or -1 if the array does not contain such element.
*/
public inline fun CharArray.indexOfLast(predicate: (Char) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun Array.last(): T {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun ByteArray.last(): Byte {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun ShortArray.last(): Short {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun IntArray.last(): Int {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun LongArray.last(): Long {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun FloatArray.last(): Float {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun DoubleArray.last(): Double {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun BooleanArray.last(): Boolean {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element.
*
* @throws NoSuchElementException if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun CharArray.last(): Char {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return this[lastIndex]
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun Array.last(predicate: (T) -> Boolean): T {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun ByteArray.last(predicate: (Byte) -> Boolean): Byte {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun ShortArray.last(predicate: (Short) -> Boolean): Short {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun IntArray.last(predicate: (Int) -> Boolean): Int {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun LongArray.last(predicate: (Long) -> Boolean): Long {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun FloatArray.last(predicate: (Float) -> Boolean): Float {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun DoubleArray.last(predicate: (Double) -> Boolean): Double {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun BooleanArray.last(predicate: (Boolean) -> Boolean): Boolean {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
*
* @throws NoSuchElementException if no such element is found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun CharArray.last(predicate: (Char) -> Boolean): Char {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun <@kotlin.internal.OnlyInputTypes T> Array.lastIndexOf(element: T): Int {
if (element == null) {
for (index in indices.reversed()) {
if (this[index] == null) {
return index
}
}
} else {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun ByteArray.lastIndexOf(element: Byte): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun ShortArray.lastIndexOf(element: Short): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun IntArray.lastIndexOf(element: Int): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun LongArray.lastIndexOf(element: Long): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfLast { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun FloatArray.lastIndexOf(element: Float): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfLast { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun DoubleArray.lastIndexOf(element: Double): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun BooleanArray.lastIndexOf(element: Boolean): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
*/
public fun CharArray.lastIndexOf(element: Char): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
return index
}
}
return -1
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun Array.lastOrNull(): T? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun ByteArray.lastOrNull(): Byte? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun ShortArray.lastOrNull(): Short? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun IntArray.lastOrNull(): Int? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun LongArray.lastOrNull(): Long? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun FloatArray.lastOrNull(): Float? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun DoubleArray.lastOrNull(): Double? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun BooleanArray.lastOrNull(): Boolean? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*
* @sample samples.collections.Collections.Elements.last
*/
public fun CharArray.lastOrNull(): Char? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun Array.lastOrNull(predicate: (T) -> Boolean): T? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun ByteArray.lastOrNull(predicate: (Byte) -> Boolean): Byte? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun ShortArray.lastOrNull(predicate: (Short) -> Boolean): Short? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun IntArray.lastOrNull(predicate: (Int) -> Boolean): Int? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun LongArray.lastOrNull(predicate: (Long) -> Boolean): Long? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun FloatArray.lastOrNull(predicate: (Float) -> Boolean): Float? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun DoubleArray.lastOrNull(predicate: (Double) -> Boolean): Double? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun BooleanArray.lastOrNull(predicate: (Boolean) -> Boolean): Boolean? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*
* @sample samples.collections.Collections.Elements.last
*/
public inline fun CharArray.lastOrNull(predicate: (Char) -> Boolean): Char? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun Array.random(): T {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun ByteArray.random(): Byte {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun ShortArray.random(): Short {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun IntArray.random(): Int {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun LongArray.random(): Long {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun FloatArray.random(): Float {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun DoubleArray.random(): Double {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun BooleanArray.random(): Boolean {
return random(Random)
}
/**
* Returns a random element from this array.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun CharArray.random(): Char {
return random(Random)
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun Array.random(random: Random): T {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun ByteArray.random(random: Random): Byte {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun ShortArray.random(random: Random): Short {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun IntArray.random(random: Random): Int {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun LongArray.random(random: Random): Long {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun FloatArray.random(random: Random): Float {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun DoubleArray.random(random: Random): Double {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun BooleanArray.random(random: Random): Boolean {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness.
*
* @throws NoSuchElementException if this array is empty.
*/
@SinceKotlin("1.3")
public fun CharArray.random(random: Random): Char {
if (isEmpty())
throw NoSuchElementException("Array is empty.")
return get(random.nextInt(size))
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun Array.randomOrNull(): T? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun ByteArray.randomOrNull(): Byte? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun ShortArray.randomOrNull(): Short? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun IntArray.randomOrNull(): Int? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun LongArray.randomOrNull(): Long? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun FloatArray.randomOrNull(): Float? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun DoubleArray.randomOrNull(): Double? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun BooleanArray.randomOrNull(): Boolean? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
@kotlin.internal.InlineOnly
public inline fun CharArray.randomOrNull(): Char? {
return randomOrNull(Random)
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun Array.randomOrNull(random: Random): T? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun ByteArray.randomOrNull(random: Random): Byte? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun ShortArray.randomOrNull(random: Random): Short? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun IntArray.randomOrNull(random: Random): Int? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun LongArray.randomOrNull(random: Random): Long? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun FloatArray.randomOrNull(random: Random): Float? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun DoubleArray.randomOrNull(random: Random): Double? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun BooleanArray.randomOrNull(random: Random): Boolean? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns a random element from this array using the specified source of randomness, or `null` if this array is empty.
*/
@SinceKotlin("1.4")
public fun CharArray.randomOrNull(random: Random): Char? {
if (isEmpty())
return null
return get(random.nextInt(size))
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun Array.single(): T {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun ByteArray.single(): Byte {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun ShortArray.single(): Short {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun IntArray.single(): Int {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun LongArray.single(): Long {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun FloatArray.single(): Float {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun DoubleArray.single(): Double {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun BooleanArray.single(): Boolean {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
public fun CharArray.single(): Char {
return when (size) {
0 -> throw NoSuchElementException("Array is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Array has more than one element.")
}
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun Array.single(predicate: (T) -> Boolean): T {
var single: T? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as T
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun ByteArray.single(predicate: (Byte) -> Boolean): Byte {
var single: Byte? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Byte
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun ShortArray.single(predicate: (Short) -> Boolean): Short {
var single: Short? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Short
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun IntArray.single(predicate: (Int) -> Boolean): Int {
var single: Int? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Int
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun LongArray.single(predicate: (Long) -> Boolean): Long {
var single: Long? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Long
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun FloatArray.single(predicate: (Float) -> Boolean): Float {
var single: Float? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Float
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun DoubleArray.single(predicate: (Double) -> Boolean): Double {
var single: Double? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Double
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun BooleanArray.single(predicate: (Boolean) -> Boolean): Boolean {
var single: Boolean? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Boolean
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
public inline fun CharArray.single(predicate: (Char) -> Boolean): Char {
var single: Char? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as Char
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun Array.singleOrNull(): T? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun ByteArray.singleOrNull(): Byte? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun ShortArray.singleOrNull(): Short? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun IntArray.singleOrNull(): Int? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun LongArray.singleOrNull(): Long? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun FloatArray.singleOrNull(): Float? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun DoubleArray.singleOrNull(): Double? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun BooleanArray.singleOrNull(): Boolean? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
public fun CharArray.singleOrNull(): Char? {
return if (size == 1) this[0] else null
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun Array.singleOrNull(predicate: (T) -> Boolean): T? {
var single: T? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun ByteArray.singleOrNull(predicate: (Byte) -> Boolean): Byte? {
var single: Byte? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun ShortArray.singleOrNull(predicate: (Short) -> Boolean): Short? {
var single: Short? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun IntArray.singleOrNull(predicate: (Int) -> Boolean): Int? {
var single: Int? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun LongArray.singleOrNull(predicate: (Long) -> Boolean): Long? {
var single: Long? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun FloatArray.singleOrNull(predicate: (Float) -> Boolean): Float? {
var single: Float? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun DoubleArray.singleOrNull(predicate: (Double) -> Boolean): Double? {
var single: Double? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun BooleanArray.singleOrNull(predicate: (Boolean) -> Boolean): Boolean? {
var single: Boolean? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns the single element matching the given [predicate], or `null` if element was not found or more than one element was found.
*/
public inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): Char? {
var single: Char? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) return null
single = element
found = true
}
}
if (!found) return null
return single
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun Array.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.drop(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun Array.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.dropLast(n: Int): List {
require(n >= 0) { "Requested element count $n is less than zero." }
return take((size - n).coerceAtLeast(0))
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun Array.dropLastWhile(predicate: (T) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun ShortArray.dropLastWhile(predicate: (Short) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun FloatArray.dropLastWhile(predicate: (Float) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun DoubleArray.dropLastWhile(predicate: (Double) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun BooleanArray.dropLastWhile(predicate: (Boolean) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List {
for (index in lastIndex downTo 0) {
if (!predicate(this[index])) {
return take(index + 1)
}
}
return emptyList()
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun Array.dropWhile(predicate: (T) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun CharArray.dropWhile(predicate: (Char) -> Boolean): List {
var yielding = false
val list = ArrayList()
for (item in this)
if (yielding)
list.add(item)
else if (!predicate(item)) {
list.add(item)
yielding = true
}
return list
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun Array.filter(predicate: (T) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun ByteArray.filter(predicate: (Byte) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun ShortArray.filter(predicate: (Short) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun IntArray.filter(predicate: (Int) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun LongArray.filter(predicate: (Long) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun FloatArray.filter(predicate: (Float) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun DoubleArray.filter(predicate: (Double) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun BooleanArray.filter(predicate: (Boolean) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun CharArray.filter(predicate: (Char) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun Array.filterIndexed(predicate: (index: Int, T) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun ByteArray.filterIndexed(predicate: (index: Int, Byte) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun ShortArray.filterIndexed(predicate: (index: Int, Short) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun IntArray.filterIndexed(predicate: (index: Int, Int) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun LongArray.filterIndexed(predicate: (index: Int, Long) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun FloatArray.filterIndexed(predicate: (index: Int, Float) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun DoubleArray.filterIndexed(predicate: (index: Int, Double) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun BooleanArray.filterIndexed(predicate: (index: Int, Boolean) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexed
*/
public inline fun CharArray.filterIndexed(predicate: (index: Int, Char) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > Array.filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > ByteArray.filterIndexedTo(destination: C, predicate: (index: Int, Byte) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > ShortArray.filterIndexedTo(destination: C, predicate: (index: Int, Short) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > IntArray.filterIndexedTo(destination: C, predicate: (index: Int, Int) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > LongArray.filterIndexedTo(destination: C, predicate: (index: Int, Long) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > FloatArray.filterIndexedTo(destination: C, predicate: (index: Int, Float) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > DoubleArray.filterIndexedTo(destination: C, predicate: (index: Int, Double) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > BooleanArray.filterIndexedTo(destination: C, predicate: (index: Int, Boolean) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
* @param [predicate] function that takes the index of an element and the element itself
* and returns the result of predicate evaluation on the element.
*
* @sample samples.collections.Collections.Filtering.filterIndexedTo
*/
public inline fun > CharArray.filterIndexedTo(destination: C, predicate: (index: Int, Char) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) destination.add(element)
}
return destination
}
/**
* Returns a list containing all elements that are instances of specified type parameter R.
*
* @sample samples.collections.Collections.Filtering.filterIsInstance
*/
public inline fun Array<*>.filterIsInstance(): List<@kotlin.internal.NoInfer R> {
return filterIsInstanceTo(ArrayList())
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterIsInstanceTo
*/
public inline fun > Array<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun Array.filterNot(predicate: (T) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun ByteArray.filterNot(predicate: (Byte) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun ShortArray.filterNot(predicate: (Short) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun IntArray.filterNot(predicate: (Int) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun LongArray.filterNot(predicate: (Long) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun FloatArray.filterNot(predicate: (Float) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun DoubleArray.filterNot(predicate: (Double) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun BooleanArray.filterNot(predicate: (Boolean) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*
* @sample samples.collections.Collections.Filtering.filter
*/
public inline fun CharArray.filterNot(predicate: (Char) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements that are not `null`.
*
* @sample samples.collections.Collections.Filtering.filterNotNull
*/
public fun Array.filterNotNull(): List {
return filterNotNullTo(ArrayList())
}
/**
* Appends all elements that are not `null` to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterNotNullTo
*/
public fun , T : Any> Array.filterNotNullTo(destination: C): C {
for (element in this) if (element != null) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > Array.filterNotTo(destination: C, predicate: (T) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > ByteArray.filterNotTo(destination: C, predicate: (Byte) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > ShortArray.filterNotTo(destination: C, predicate: (Short) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > IntArray.filterNotTo(destination: C, predicate: (Int) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > LongArray.filterNotTo(destination: C, predicate: (Long) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > FloatArray.filterNotTo(destination: C, predicate: (Float) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > DoubleArray.filterNotTo(destination: C, predicate: (Double) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > BooleanArray.filterNotTo(destination: C, predicate: (Boolean) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > CharArray.filterNotTo(destination: C, predicate: (Char) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > Array.filterTo(destination: C, predicate: (T) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > ByteArray.filterTo(destination: C, predicate: (Byte) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > ShortArray.filterTo(destination: C, predicate: (Short) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > IntArray.filterTo(destination: C, predicate: (Int) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > LongArray.filterTo(destination: C, predicate: (Long) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > FloatArray.filterTo(destination: C, predicate: (Float) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > DoubleArray.filterTo(destination: C, predicate: (Double) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > BooleanArray.filterTo(destination: C, predicate: (Boolean) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*
* @sample samples.collections.Collections.Filtering.filterTo
*/
public inline fun > CharArray.filterTo(destination: C, predicate: (Char) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun Array.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun ByteArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun ShortArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun IntArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun LongArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun FloatArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun DoubleArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun BooleanArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at indices in the specified [indices] range.
*/
public fun CharArray.slice(indices: IntRange): List {
if (indices.isEmpty()) return listOf()
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun Array.slice(indices: Iterable): List {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return emptyList()
val list = ArrayList(size)
for (index in indices) {
list.add(get(index))
}
return list
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun ByteArray.slice(indices: Iterable): List {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return emptyList()
val list = ArrayList(size)
for (index in indices) {
list.add(get(index))
}
return list
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun ShortArray.slice(indices: Iterable): List {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return emptyList()
val list = ArrayList(size)
for (index in indices) {
list.add(get(index))
}
return list
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun IntArray.slice(indices: Iterable): List {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return emptyList()
val list = ArrayList(size)
for (index in indices) {
list.add(get(index))
}
return list
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun LongArray.slice(indices: Iterable): List {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return emptyList()
val list = ArrayList(size)
for (index in indices) {
list.add(get(index))
}
return list
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun FloatArray.slice(indices: Iterable): List {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return emptyList()
val list = ArrayList(size)
for (index in indices) {
list.add(get(index))
}
return list
}
/**
* Returns a list containing elements at specified [indices].
*/
public fun DoubleArray.slice(indices: Iterable