Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("ArraysKt")
package kotlin
//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//
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.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun Array.component1(): T {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun BooleanArray.component1(): Boolean {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ByteArray.component1(): Byte {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun CharArray.component1(): Char {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun DoubleArray.component1(): Double {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun FloatArray.component1(): Float {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun IntArray.component1(): Int {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun LongArray.component1(): Long {
return get(0)
}
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ShortArray.component1(): Short {
return get(0)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun Array.component2(): T {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun BooleanArray.component2(): Boolean {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ByteArray.component2(): Byte {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun CharArray.component2(): Char {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun DoubleArray.component2(): Double {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun FloatArray.component2(): Float {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun IntArray.component2(): Int {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun LongArray.component2(): Long {
return get(1)
}
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ShortArray.component2(): Short {
return get(1)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun Array.component3(): T {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun BooleanArray.component3(): Boolean {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ByteArray.component3(): Byte {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun CharArray.component3(): Char {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun DoubleArray.component3(): Double {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun FloatArray.component3(): Float {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun IntArray.component3(): Int {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun LongArray.component3(): Long {
return get(2)
}
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ShortArray.component3(): Short {
return get(2)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun Array.component4(): T {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun BooleanArray.component4(): Boolean {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ByteArray.component4(): Byte {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun CharArray.component4(): Char {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun DoubleArray.component4(): Double {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun FloatArray.component4(): Float {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun IntArray.component4(): Int {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun LongArray.component4(): Long {
return get(3)
}
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ShortArray.component4(): Short {
return get(3)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun Array.component5(): T {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun BooleanArray.component5(): Boolean {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ByteArray.component5(): Byte {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun CharArray.component5(): Char {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun DoubleArray.component5(): Double {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun FloatArray.component5(): Float {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun IntArray.component5(): Int {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun LongArray.component5(): Long {
return get(4)
}
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
public inline operator fun ShortArray.component5(): Short {
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 BooleanArray.contains(element: Boolean): 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 CharArray.contains(element: Char): 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 FloatArray.contains(element: Float): 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 ShortArray.contains(element: Short): Boolean {
return indexOf(element) >= 0
}
/**
* Returns `true` if [element] is found in the collection.
*/
@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure. Replacement will be provided in beta4.")
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
public operator fun Array.contains(element: T): Boolean {
return contains(element)
}
/**
* Returns `true` if [element] is found in the array.
* Allows to overcome type-safety restriction of `contains` that requires to pass an element of type `T`.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun Array.containsRaw(element: Any?): Boolean {
return contains(element)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
public 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.
*/
public 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.
*/
public 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.
*/
public fun CharArray.elementAt(index: Int): Char {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*/
public 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.
*/
public 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.
*/
public 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.
*/
public 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.
*/
public fun ShortArray.elementAt(index: Int): Short {
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.
*/
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.
*/
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.
*/
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.
*/
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 the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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 `null` if the [index] is out of bounds of this array.
*/
public fun Array.elementAtOrNull(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 BooleanArray.elementAtOrNull(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 ByteArray.elementAtOrNull(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 CharArray.elementAtOrNull(index: Int): Char? {
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.elementAtOrNull(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 FloatArray.elementAtOrNull(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 IntArray.elementAtOrNull(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.elementAtOrNull(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 ShortArray.elementAtOrNull(index: Int): Short? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
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.
*/
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.
*/
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.
*/
public inline fun CharArray.find(predicate: (Char) -> Boolean): Char? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
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.
*/
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.
*/
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.
*/
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.
*/
public inline fun ShortArray.find(predicate: (Short) -> Boolean): Short? {
return firstOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
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.
*/
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.
*/
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.
*/
public inline fun CharArray.findLast(predicate: (Char) -> Boolean): Char? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
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.
*/
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.
*/
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.
*/
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.
*/
public inline fun ShortArray.findLast(predicate: (Short) -> Boolean): Short? {
return lastOrNull(predicate)
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun Array.first(): T {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun BooleanArray.first(): Boolean {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun ByteArray.first(): Byte {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun CharArray.first(): Char {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun DoubleArray.first(): Double {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun FloatArray.first(): Float {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun IntArray.first(): Int {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun LongArray.first(): Long {
if (isEmpty())
throw NoSuchElementException("Collection is empty.")
return this[0]
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun ShortArray.first(): Short {
if (isEmpty())
throw NoSuchElementException("Collection 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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("No element matching predicate was found.")
}
/**
* 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 BooleanArray.firstOrNull(): Boolean? {
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 CharArray.firstOrNull(): Char? {
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 FloatArray.firstOrNull(): Float? {
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 ShortArray.firstOrNull(): Short? {
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 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 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 CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? {
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 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 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 ShortArray.firstOrNull(predicate: (Short) -> Boolean): Short? {
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.
*/
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.
*/
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.
*/
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.
*/
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 the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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 `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 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 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 CharArray.getOrNull(index: Int): Char? {
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 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 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 ShortArray.getOrNull(index: Int): Short? {
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 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 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 CharArray.indexOf(element: Char): 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 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 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 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 collection does not contain element.
*/
@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure. Replacement will be provided in beta4.")
@kotlin.jvm.JvmName("indexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun Array.indexOf(element: T): Int {
return indexOf(element)
}
/**
* 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 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 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 CharArray.indexOfFirst(predicate: (Char) -> 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 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 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 ShortArray.indexOfFirst(predicate: (Short) -> 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 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 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 CharArray.indexOfLast(predicate: (Char) -> 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 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 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 ShortArray.indexOfLast(predicate: (Short) -> Boolean): Int {
for (index in indices.reversed()) {
if (predicate(this[index])) {
return index
}
}
return -1
}
/**
* Returns first index of [element], or -1 if the array does not contain element.
* Allows to overcome type-safety restriction of `indexOf` that requires to pass an element of type `T`.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun Array.indexOfRaw(element: Any?): Int {
return indexOf(element)
}
/**
* Returns the last element.
* @throws [NoSuchElementException] if the array is empty.
*/
public fun Array.last(): T {
if (isEmpty())
throw NoSuchElementException("Collection 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("Collection 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("Collection 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("Collection 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("Collection 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("Collection 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("Collection 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("Collection 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("Collection 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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("Collection doesn't contain any 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 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 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 CharArray.lastIndexOf(element: Char): 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 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 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 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 collection does not contain element.
*/
@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure. Replacement will be provided in beta4.")
@kotlin.jvm.JvmName("lastIndexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun Array.lastIndexOf(element: T): Int {
return lastIndexOf(element)
}
/**
* Returns last index of [element], or -1 if the array does not contain element.
* Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun Array.lastIndexOfRaw(element: Any?): Int {
return lastIndexOf(element)
}
/**
* 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 BooleanArray.lastOrNull(): Boolean? {
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 CharArray.lastOrNull(): Char? {
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 FloatArray.lastOrNull(): Float? {
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 ShortArray.lastOrNull(): Short? {
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 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 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 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 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 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 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 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 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection is empty.")
1 -> this[0]
else -> throw IllegalArgumentException("Collection 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("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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 BooleanArray.single(predicate: (Boolean) -> Boolean): Boolean {
var single: Boolean? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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 ByteArray.single(predicate: (Byte) -> Boolean): Byte {
var single: Byte? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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 CharArray.single(predicate: (Char) -> Boolean): Char {
var single: Char? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
return single as Char
}
/**
* 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("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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 FloatArray.single(predicate: (Float) -> Boolean): Float {
var single: Float? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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 IntArray.single(predicate: (Int) -> Boolean): Int {
var single: Int? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching 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 ShortArray.single(predicate: (Short) -> Boolean): Short {
var single: Short? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
return single as Short
}
/**
* 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 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 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 CharArray.singleOrNull(): Char? {
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 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 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 ShortArray.singleOrNull(): Short? {
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 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 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 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 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 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 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 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 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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." })
if (n == 0)
return toList()
if (n >= size)
return emptyList()
val list = ArrayList(size - n)
for (index in n..size - 1) {
list.add(this[index])
}
return list
}
/**
* 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 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 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 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 [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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 BooleanArray.filter(predicate: (Boolean) -> 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 CharArray.filter(predicate: (Char) -> 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 FloatArray.filter(predicate: (Float) -> 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 ShortArray.filter(predicate: (Short) -> Boolean): List {
return filterTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun Array.filterIndexed(predicate: (Int, T) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun BooleanArray.filterIndexed(predicate: (Int, Boolean) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun ByteArray.filterIndexed(predicate: (Int, Byte) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun CharArray.filterIndexed(predicate: (Int, Char) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun DoubleArray.filterIndexed(predicate: (Int, Double) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun FloatArray.filterIndexed(predicate: (Int, Float) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun IntArray.filterIndexed(predicate: (Int, Int) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun LongArray.filterIndexed(predicate: (Int, Long) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Returns a list containing only elements matching the given [predicate].
*/
public inline fun ShortArray.filterIndexed(predicate: (Int, Short) -> Boolean): List {
return filterIndexedTo(ArrayList(), predicate)
}
/**
* Appends all elements matching the given [predicate] to the given [destination].
*/
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].
*/
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].
*/
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].
*/
public inline fun > CharArray.filterIndexedTo(destination: C, predicate: (Int, Char) -> 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].
*/
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].
*/
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].
*/
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].
*/
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].
*/
public inline fun > ShortArray.filterIndexedTo(destination: C, predicate: (Int, Short) -> Boolean): C {
forEachIndexed { index, element ->
if (predicate(index, element)) 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 BooleanArray.filterNot(predicate: (Boolean) -> 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 CharArray.filterNot(predicate: (Char) -> 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 FloatArray.filterNot(predicate: (Float) -> 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 ShortArray.filterNot(predicate: (Short) -> 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 > 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 > 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 > CharArray.filterNotTo(destination: C, predicate: (Char) -> 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 > 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 > 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 > ShortArray.filterNotTo(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 > 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 > 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 > 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 > CharArray.filterTo(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 > 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 > 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 > 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 > ShortArray.filterTo(destination: C, predicate: (Short) -> 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 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 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 CharArray.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 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 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 ShortArray.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 listOf()
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 listOf()
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 listOf()
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 listOf()
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