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-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
@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.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component1(): T {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component1(): Byte {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component1(): Short {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component1(): Int {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component1(): Long {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component1(): Float {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component1(): Double {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component1(): Boolean {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component1(): Char {
return get(0)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component2(): T {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component2(): Byte {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component2(): Short {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component2(): Int {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component2(): Long {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component2(): Float {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component2(): Double {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component2(): Boolean {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component2(): Char {
return get(1)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component3(): T {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component3(): Byte {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component3(): Short {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component3(): Int {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component3(): Long {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component3(): Float {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component3(): Double {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component3(): Boolean {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component3(): Char {
return get(2)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component4(): T {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component4(): Byte {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component4(): Short {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component4(): Int {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component4(): Long {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component4(): Float {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component4(): Double {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component4(): Boolean {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun CharArray.component4(): Char {
return get(3)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun Array.component5(): T {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ByteArray.component5(): Byte {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun ShortArray.component5(): Short {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component5(): Int {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun LongArray.component5(): Long {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun FloatArray.component5(): Float {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun DoubleArray.component5(): Double {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun BooleanArray.component5(): Boolean {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@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.
*/
public operator fun FloatArray.contains(element: Float): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the array.
*/
public operator fun DoubleArray.contains(element: Double): Boolean {
return indexOf(element) >= 0
}
/**
* 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.
*/
@kotlin.internal.InlineOnly
public inline fun Array.elementAt(index: Int): T {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.elementAt(index: Int): Byte {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.elementAt(index: Int): Short {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.elementAt(index: Int): Int {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.elementAt(index: Int): Long {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.elementAt(index: Int): Float {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.elementAt(index: Int): Double {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.elementAt(index: Int): Boolean {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.elementAt(index: Int): Char {
return get(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 Array.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Byte): Byte {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Short): Short {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Int): Int {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Long): Long {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Float): Float {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Double): Double {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Boolean): Boolean {
return if (index >= 0 && index <= lastIndex) 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.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@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.
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.findLast(predicate: (Char) -> Boolean): Char? {
return lastOrNull(predicate)
}
/**
* Returns 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 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 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 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 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 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 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 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 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 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) 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 {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun Array.getOrNull(index: Int): T? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun ByteArray.getOrNull(index: Int): Byte? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun ShortArray.getOrNull(index: Int): Short? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun IntArray.getOrNull(index: Int): Int? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun LongArray.getOrNull(index: Int): Long? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun FloatArray.getOrNull(index: Int): Float? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun DoubleArray.getOrNull(index: Int): Double? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun BooleanArray.getOrNull(index: Int): Boolean? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*/
public fun CharArray.getOrNull(index: Int): Char? {
return if (index >= 0 && index <= lastIndex) 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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
public fun Array.lastOrNull(): T? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun ByteArray.lastOrNull(): Byte? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun ShortArray.lastOrNull(): Short? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun IntArray.lastOrNull(): Int? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun LongArray.lastOrNull(): Long? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun FloatArray.lastOrNull(): Float? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun DoubleArray.lastOrNull(): Double? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
public fun BooleanArray.lastOrNull(): Boolean? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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 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.")
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.")
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.")
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.")
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.")
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.")
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.")
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.")
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.")
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
public inline fun Array.filter(predicate: (T) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun ByteArray.filter(predicate: (Byte) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun ShortArray.filter(predicate: (Short) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun IntArray.filter(predicate: (Int) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun LongArray.filter(predicate: (Long) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun FloatArray.filter(predicate: (Float) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun DoubleArray.filter(predicate: (Double) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun BooleanArray.filter(predicate: (Boolean) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
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.
*/
public inline fun Array.filterIndexed(predicate: (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.
*/
public inline fun ByteArray.filterIndexed(predicate: (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.
*/
public inline fun ShortArray.filterIndexed(predicate: (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.
*/
public inline fun IntArray.filterIndexed(predicate: (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.
*/
public inline fun LongArray.filterIndexed(predicate: (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.
*/
public inline fun FloatArray.filterIndexed(predicate: (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.
*/
public inline fun DoubleArray.filterIndexed(predicate: (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.
*/
public inline fun BooleanArray.filterIndexed(predicate: (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.
*/
public inline fun CharArray.filterIndexed(predicate: (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.
*/
public inline fun > Array.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > ByteArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > ShortArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > IntArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > LongArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > FloatArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > DoubleArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > BooleanArray.filterIndexedTo(destination: C, predicate: (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.
*/
public inline fun > CharArray.filterIndexedTo(destination: C, predicate: (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.
*/
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].
*/
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].
*/
public inline fun Array.filterNot(predicate: (T) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun ByteArray.filterNot(predicate: (Byte) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun ShortArray.filterNot(predicate: (Short) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun IntArray.filterNot(predicate: (Int) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun LongArray.filterNot(predicate: (Long) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun FloatArray.filterNot(predicate: (Float) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun DoubleArray.filterNot(predicate: (Double) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun BooleanArray.filterNot(predicate: (Boolean) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
public inline fun CharArray.filterNot(predicate: (Char) -> Boolean): List {
return filterNotTo(ArrayList(), predicate)
}
/**
* Returns a list containing all elements that are not `null`.
*/
public fun Array.filterNotNull(): List {
return filterNotNullTo(ArrayList())
}
/**
* Appends all elements that are not `null` to the given [destination].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
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): 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 BooleanArray.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 CharArray.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 an array containing elements of this array at specified [indices].
*/
public fun Array.sliceArray(indices: Collection): Array {
val result = arrayOfNulls(this, indices.size)
var targetIndex = 0
for (sourceIndex in indices) {
result[targetIndex++] = this[sourceIndex]
}
return result
}
/**
* Returns an array containing elements of this array at specified [indices].
*/
public fun ByteArray.sliceArray(indices: Collection