Implement first, last & single extension functions for UArrays

This commit is contained in:
Abduqodiri Qurbonzoda
2019-01-29 12:46:24 +03:00
committed by Ilya Gorbunov
parent 299fac8e2d
commit 92cd84682c
5 changed files with 1010 additions and 57 deletions
@@ -215,6 +215,478 @@ public inline operator fun UShortArray.component5(): UShort {
return get(4) return get(4)
} }
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.elementAt(index: Int): UInt {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.elementAt(index: Int): ULong {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.elementAt(index: Int): UByte {
return get(index)
}
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAt
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.elementAt(index: Int): UShort {
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.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.elementAtOrElse(index: Int, defaultValue: (Int) -> UInt): UInt {
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.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.elementAtOrElse(index: Int, defaultValue: (Int) -> ULong): ULong {
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.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.elementAtOrElse(index: Int, defaultValue: (Int) -> UByte): UByte {
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.
*
* @sample samples.collections.Collections.Elements.elementAtOrElse
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.elementAtOrElse(index: Int, defaultValue: (Int) -> UShort): UShort {
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.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.elementAtOrNull(index: Int): UInt? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.elementAtOrNull(index: Int): ULong? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.elementAtOrNull(index: Int): UByte? {
return this.getOrNull(index)
}
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.elementAtOrNull
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.elementAtOrNull(index: Int): UShort? {
return this.getOrNull(index)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.find(predicate: (UInt) -> Boolean): UInt? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.find(predicate: (ULong) -> Boolean): ULong? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.find(predicate: (UByte) -> Boolean): UByte? {
return firstOrNull(predicate)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.find(predicate: (UShort) -> Boolean): UShort? {
return firstOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.findLast(predicate: (UInt) -> Boolean): UInt? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.findLast(predicate: (ULong) -> Boolean): ULong? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.findLast(predicate: (UByte) -> Boolean): UByte? {
return lastOrNull(predicate)
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.findLast(predicate: (UShort) -> Boolean): UShort? {
return lastOrNull(predicate)
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.first(): UInt {
return storage.first().toUInt()
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.first(): ULong {
return storage.first().toULong()
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.first(): UByte {
return storage.first().toUByte()
}
/**
* Returns first element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.first(): UShort {
return storage.first().toUShort()
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.first(predicate: (UInt) -> Boolean): UInt {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.first(predicate: (ULong) -> Boolean): ULong {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.first(predicate: (UByte) -> Boolean): UByte {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.first(predicate: (UShort) -> Boolean): UShort {
for (element in this) if (predicate(element)) return element
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the first element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.firstOrNull(): UInt? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.firstOrNull(): ULong? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UByteArray.firstOrNull(): UByte? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UShortArray.firstOrNull(): UShort? {
return if (isEmpty()) null else this[0]
}
/**
* Returns the first element matching the given [predicate], or `null` if element was not found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.firstOrNull(predicate: (UInt) -> Boolean): UInt? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.firstOrNull(predicate: (ULong) -> Boolean): ULong? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.firstOrNull(predicate: (UByte) -> Boolean): UByte? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.firstOrNull(predicate: (UShort) -> Boolean): UShort? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.getOrElse(index: Int, defaultValue: (Int) -> UInt): UInt {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.getOrElse(index: Int, defaultValue: (Int) -> ULong): ULong {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.getOrElse(index: Int, defaultValue: (Int) -> UByte): UByte {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.getOrElse(index: Int, defaultValue: (Int) -> UShort): UShort {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.getOrNull(index: Int): UInt? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.getOrNull(index: Int): ULong? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UByteArray.getOrNull(index: Int): UByte? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UShortArray.getOrNull(index: Int): UShort? {
return if (index >= 0 && index <= lastIndex) get(index) else null
}
/** /**
* Returns first index of [element], or -1 if the array does not contain element. * Returns first index of [element], or -1 if the array does not contain element.
*/ */
@@ -335,6 +807,110 @@ public inline fun UShortArray.indexOfLast(predicate: (UShort) -> Boolean): Int {
return storage.indexOfLast { predicate(it.toUShort()) } return storage.indexOfLast { predicate(it.toUShort()) }
} }
/**
* Returns the last element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.last(): UInt {
return storage.last().toUInt()
}
/**
* Returns the last element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.last(): ULong {
return storage.last().toULong()
}
/**
* Returns the last element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.last(): UByte {
return storage.last().toUByte()
}
/**
* Returns the last element.
* @throws [NoSuchElementException] if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.last(): UShort {
return storage.last().toUShort()
}
/**
* Returns the last element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.last(predicate: (UInt) -> Boolean): UInt {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.last(predicate: (ULong) -> Boolean): ULong {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.last(predicate: (UByte) -> Boolean): UByte {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/**
* Returns the last element matching the given [predicate].
* @throws [NoSuchElementException] if no such element is found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.last(predicate: (UShort) -> Boolean): UShort {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
throw NoSuchElementException("Array contains no element matching the predicate.")
}
/** /**
* Returns last index of [element], or -1 if the array does not contain element. * Returns last index of [element], or -1 if the array does not contain element.
*/ */
@@ -375,6 +951,98 @@ public inline fun UShortArray.lastIndexOf(element: UShort): Int {
return storage.lastIndexOf(element.toShort()) return storage.lastIndexOf(element.toShort())
} }
/**
* Returns the last element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.lastOrNull(): UInt? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.lastOrNull(): ULong? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UByteArray.lastOrNull(): UByte? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element, or `null` if the array is empty.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UShortArray.lastOrNull(): UShort? {
return if (isEmpty()) null else this[size - 1]
}
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.lastOrNull(predicate: (UInt) -> Boolean): UInt? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.lastOrNull(predicate: (ULong) -> Boolean): ULong? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.lastOrNull(predicate: (UByte) -> Boolean): UByte? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.lastOrNull(predicate: (UShort) -> Boolean): UShort? {
for (index in this.indices.reversed()) {
val element = this[index]
if (predicate(element)) return element
}
return null
}
/** /**
* Returns a random element from this array. * Returns a random element from this array.
* *
@@ -475,6 +1143,246 @@ public fun UShortArray.random(random: Random): UShort {
return get(random.nextInt(size)) return get(random.nextInt(size))
} }
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.single(): UInt {
return storage.single().toUInt()
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.single(): ULong {
return storage.single().toULong()
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.single(): UByte {
return storage.single().toUByte()
}
/**
* Returns the single element, or throws an exception if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.single(): UShort {
return storage.single().toUShort()
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.single(predicate: (UInt) -> Boolean): UInt {
var single: UInt? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as UInt
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.single(predicate: (ULong) -> Boolean): ULong {
var single: ULong? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as ULong
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.single(predicate: (UByte) -> Boolean): UByte {
var single: UByte? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as UByte
}
/**
* Returns the single element matching the given [predicate], or throws exception if there is no or more than one matching element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.single(predicate: (UShort) -> Boolean): UShort {
var single: UShort? = null
var found = false
for (element in this) {
if (predicate(element)) {
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
single = element
found = true
}
}
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
@Suppress("UNCHECKED_CAST")
return single as UShort
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UIntArray.singleOrNull(): UInt? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun ULongArray.singleOrNull(): ULong? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UByteArray.singleOrNull(): UByte? {
return if (size == 1) this[0] else null
}
/**
* Returns single element, or `null` if the array is empty or has more than one element.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun UShortArray.singleOrNull(): UShort? {
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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.singleOrNull(predicate: (UInt) -> Boolean): UInt? {
var single: UInt? = 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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.singleOrNull(predicate: (ULong) -> Boolean): ULong? {
var single: ULong? = 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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.singleOrNull(predicate: (UByte) -> Boolean): UByte? {
var single: UByte? = 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.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.singleOrNull(predicate: (UShort) -> Boolean): UShort? {
var single: UShort? = 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 an array of type [ByteArray], which is a view of this array where each element is a signed reinterpretation * Returns an array of type [ByteArray], which is a view of this array where each element is a signed reinterpretation
* of the corresponding element of this array. * of the corresponding element of this array.
@@ -177,3 +177,4 @@ public fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = si
public fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit { public fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit {
storage.fill(element.toShort(), fromIndex, toIndex) storage.fill(element.toShort(), fromIndex, toIndex)
} }
@@ -2315,6 +2315,18 @@ public final class kotlin/collections/UArraysKt {
public static synthetic fun fill-K6DWlUc$default ([JJIIILjava/lang/Object;)V public static synthetic fun fill-K6DWlUc$default ([JJIIILjava/lang/Object;)V
public static final fun fill-WpHrYlw ([BBII)V public static final fun fill-WpHrYlw ([BBII)V
public static synthetic fun fill-WpHrYlw$default ([BBIIILjava/lang/Object;)V public static synthetic fun fill-WpHrYlw$default ([BBIIILjava/lang/Object;)V
public static final fun firstOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun firstOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun firstOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun firstOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun getOrNull-PpDY95g ([BI)Lkotlin/UByte;
public static final fun getOrNull-nggk6HY ([SI)Lkotlin/UShort;
public static final fun getOrNull-qFRl0hI ([II)Lkotlin/UInt;
public static final fun getOrNull-r7IrZao ([JI)Lkotlin/ULong;
public static final fun lastOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun lastOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun lastOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun lastOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun plus-CFIt9YE ([ILjava/util/Collection;)[I public static final fun plus-CFIt9YE ([ILjava/util/Collection;)[I
public static final fun plus-kzHmqpY ([JLjava/util/Collection;)[J public static final fun plus-kzHmqpY ([JLjava/util/Collection;)[J
public static final fun plus-ojwP5H8 ([SLjava/util/Collection;)[S public static final fun plus-ojwP5H8 ([SLjava/util/Collection;)[S
@@ -2323,6 +2335,10 @@ public final class kotlin/collections/UArraysKt {
public static final fun random-JzugnMA ([JLkotlin/random/Random;)J public static final fun random-JzugnMA ([JLkotlin/random/Random;)J
public static final fun random-oSF2wD8 ([BLkotlin/random/Random;)B public static final fun random-oSF2wD8 ([BLkotlin/random/Random;)B
public static final fun random-s5X_as8 ([SLkotlin/random/Random;)S public static final fun random-s5X_as8 ([SLkotlin/random/Random;)S
public static final fun singleOrNull--ajY-9A ([I)Lkotlin/UInt;
public static final fun singleOrNull-GBYM_sE ([B)Lkotlin/UByte;
public static final fun singleOrNull-QwZRm1k ([J)Lkotlin/ULong;
public static final fun singleOrNull-rL5Bavg ([S)Lkotlin/UShort;
public static final fun toTypedArray--ajY-9A ([I)[Lkotlin/UInt; public static final fun toTypedArray--ajY-9A ([I)[Lkotlin/UInt;
public static final fun toTypedArray-GBYM_sE ([B)[Lkotlin/UByte; public static final fun toTypedArray-GBYM_sE ([B)[Lkotlin/UByte;
public static final fun toTypedArray-QwZRm1k ([J)[Lkotlin/ULong; public static final fun toTypedArray-QwZRm1k ([J)[Lkotlin/ULong;
@@ -260,7 +260,7 @@ object Elements : TemplateGroupBase() {
val f_elementAt = fn("elementAt(index: Int)") { val f_elementAt = fn("elementAt(index: Int)") {
includeDefault() includeDefault()
include(CharSequences, Lists) include(CharSequences, Lists, ArraysOfUnsigned)
} builder { } builder {
val index = '$' + "index" val index = '$' + "index"
doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this ${f.collection}." } doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this ${f.collection}." }
@@ -280,7 +280,7 @@ object Elements : TemplateGroupBase() {
""" """
} }
specialFor(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) { specialFor(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
inlineOnly() inlineOnly()
body { "return get(index)" } body { "return get(index)" }
} }
@@ -288,7 +288,7 @@ object Elements : TemplateGroupBase() {
val f_elementAtOrElse = fn("elementAtOrElse(index: Int, defaultValue: (Int) -> T)") { val f_elementAtOrElse = fn("elementAtOrElse(index: Int, defaultValue: (Int) -> T)") {
includeDefault() includeDefault()
include(CharSequences, Lists) include(CharSequences, Lists, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." } doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." }
sample("samples.collections.Collections.Elements.elementAtOrElse") sample("samples.collections.Collections.Elements.elementAtOrElse")
@@ -323,7 +323,7 @@ object Elements : TemplateGroupBase() {
return defaultValue(index) return defaultValue(index)
""" """
} }
specialFor(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) { specialFor(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
inlineOnly() inlineOnly()
body { body {
""" """
@@ -334,7 +334,7 @@ object Elements : TemplateGroupBase() {
} }
val f_getOrElse = fn("getOrElse(index: Int, defaultValue: (Int) -> T)") { val f_getOrElse = fn("getOrElse(index: Int, defaultValue: (Int) -> T)") {
include(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) include(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." } doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this ${f.collection}." }
returns("T") returns("T")
@@ -348,7 +348,7 @@ object Elements : TemplateGroupBase() {
val f_elementAtOrNull = fn("elementAtOrNull(index: Int)") { val f_elementAtOrNull = fn("elementAtOrNull(index: Int)") {
includeDefault() includeDefault()
include(CharSequences, Lists) include(CharSequences, Lists, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." } doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." }
sample("samples.collections.Collections.Elements.elementAtOrNull") sample("samples.collections.Collections.Elements.elementAtOrNull")
@@ -383,14 +383,14 @@ object Elements : TemplateGroupBase() {
return null return null
""" """
} }
specialFor(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) { specialFor(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
inlineOnly() inlineOnly()
body { "return this.getOrNull(index)" } body { "return this.getOrNull(index)" }
} }
} }
val f_getOrNull = fn("getOrNull(index: Int)") { val f_getOrNull = fn("getOrNull(index: Int)") {
include(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) include(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." } doc { "Returns ${f.element.prefixWithArticle()} at the given [index] or `null` if the [index] is out of bounds of this ${f.collection}." }
returns("T?") returns("T?")
@@ -403,7 +403,7 @@ object Elements : TemplateGroupBase() {
val f_first = fn("first()") { val f_first = fn("first()") {
includeDefault() includeDefault()
include(CharSequences, Lists) include(CharSequences, Lists, ArraysOfUnsigned)
} builder { } builder {
doc { """Returns first ${f.element}. doc { """Returns first ${f.element}.
@throws [NoSuchElementException] if the ${f.collection} is empty. @throws [NoSuchElementException] if the ${f.collection} is empty.
@@ -437,11 +437,16 @@ object Elements : TemplateGroupBase() {
return iterator.next() return iterator.next()
""" """
} }
specialFor(ArraysOfUnsigned) {
inlineOnly()
body { "return storage.first().to${primitive!!.name}()" }
}
} }
val f_firstOrNull = fn("firstOrNull()") { val f_firstOrNull = fn("firstOrNull()") {
includeDefault() includeDefault()
include(CharSequences, Lists) include(CharSequences, Lists, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns the first ${f.element}, or `null` if the ${f.collection} is empty." } doc { "Returns the first ${f.element}, or `null` if the ${f.collection} is empty." }
returns("T?") returns("T?")
@@ -463,7 +468,7 @@ object Elements : TemplateGroupBase() {
} }
""" """
} }
body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives) { body(CharSequences, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
""" """
return if (isEmpty()) null else this[0] return if (isEmpty()) null else this[0]
""" """
@@ -480,12 +485,15 @@ object Elements : TemplateGroupBase() {
val f_first_predicate = fn("first(predicate: (T) -> Boolean)") { val f_first_predicate = fn("first(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(CharSequences) include(CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline() inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { """Returns the first ${f.element} matching the given [predicate]. doc { """Returns the first ${f.element} matching the given [predicate].
@throws [NoSuchElementException] if no such ${f.element} is found.""" } @throws [NoSuchElementException] if no such ${f.element} is found.""" }
returns("T") returns("T")
body { body {
""" """
for (element in this) if (predicate(element)) return element for (element in this) if (predicate(element)) return element
@@ -496,9 +504,10 @@ object Elements : TemplateGroupBase() {
val f_firstOrNull_predicate = fn("firstOrNull(predicate: (T) -> Boolean)") { val f_firstOrNull_predicate = fn("firstOrNull(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(CharSequences) include(CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline() inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Returns the first ${f.element} matching the given [predicate], or `null` if ${f.element} was not found." } doc { "Returns the first ${f.element} matching the given [predicate], or `null` if ${f.element} was not found." }
returns("T?") returns("T?")
@@ -512,7 +521,7 @@ object Elements : TemplateGroupBase() {
val f_find = fn("find(predicate: (T) -> Boolean)") { val f_find = fn("find(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(CharSequences) include(CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline(Inline.Only) inline(Inline.Only)
doc { "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } doc { "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
@@ -523,7 +532,7 @@ object Elements : TemplateGroupBase() {
val f_last = fn("last()") { val f_last = fn("last()") {
includeDefault() includeDefault()
include(CharSequences, Lists) include(CharSequences, Lists, ArraysOfUnsigned)
} builder { } builder {
doc { """Returns the last ${f.element}. doc { """Returns the last ${f.element}.
@throws [NoSuchElementException] if the ${f.collection} is empty.""" } @throws [NoSuchElementException] if the ${f.collection} is empty.""" }
@@ -562,11 +571,16 @@ object Elements : TemplateGroupBase() {
return this[lastIndex] return this[lastIndex]
""" """
} }
specialFor(ArraysOfUnsigned) {
inlineOnly()
body { "return storage.last().to${primitive!!.name}()" }
}
} }
val f_lastOrNull = fn("lastOrNull()") { val f_lastOrNull = fn("lastOrNull()") {
includeDefault() includeDefault()
include(Lists, CharSequences) include(Lists, CharSequences, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns the last ${f.element}, or `null` if the ${f.collection} is empty." } doc { "Returns the last ${f.element}, or `null` if the ${f.collection} is empty." }
returns("T?") returns("T?")
@@ -602,7 +616,7 @@ object Elements : TemplateGroupBase() {
return if (isEmpty()) null else this[length - 1] return if (isEmpty()) null else this[length - 1]
""" """
} }
body(Lists, ArraysOfObjects, ArraysOfPrimitives) { body(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
""" """
return if (isEmpty()) null else this[size - 1] return if (isEmpty()) null else this[size - 1]
""" """
@@ -611,9 +625,10 @@ object Elements : TemplateGroupBase() {
val f_last_predicate = fn("last(predicate: (T) -> Boolean)") { val f_last_predicate = fn("last(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(Lists, CharSequences) include(Lists, CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline() inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { """Returns the last ${f.element} matching the given [predicate]. doc { """Returns the last ${f.element} matching the given [predicate].
@throws [NoSuchElementException] if no such ${f.element} is found.""" } @throws [NoSuchElementException] if no such ${f.element} is found.""" }
@@ -634,7 +649,7 @@ object Elements : TemplateGroupBase() {
""" """
} }
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects) { body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
""" """
for (index in this.indices.reversed()) { for (index in this.indices.reversed()) {
val element = this[index] val element = this[index]
@@ -657,9 +672,11 @@ object Elements : TemplateGroupBase() {
val f_lastOrNull_predicate = fn("lastOrNull(predicate: (T) -> Boolean)") { val f_lastOrNull_predicate = fn("lastOrNull(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(Lists, CharSequences) include(Lists, CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline() inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } doc { "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
returns("T?") returns("T?")
body { body {
@@ -674,7 +691,7 @@ object Elements : TemplateGroupBase() {
""" """
} }
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects) { body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
""" """
for (index in this.indices.reversed()) { for (index in this.indices.reversed()) {
val element = this[index] val element = this[index]
@@ -698,7 +715,7 @@ object Elements : TemplateGroupBase() {
val f_findLast = fn("findLast(predicate: (T) -> Boolean)") { val f_findLast = fn("findLast(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(Lists, CharSequences) include(Lists, CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline(Inline.Only) inline(Inline.Only)
doc { "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } doc { "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
@@ -708,7 +725,7 @@ object Elements : TemplateGroupBase() {
val f_single = fn("single()") { val f_single = fn("single()") {
includeDefault() includeDefault()
include(Lists, CharSequences) include(Lists, CharSequences, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns the single ${f.element}, or throws an exception if the ${f.collection} is empty or has more than one ${f.element}." } doc { "Returns the single ${f.element}, or throws an exception if the ${f.collection} is empty or has more than one ${f.element}." }
returns("T") returns("T")
@@ -748,11 +765,16 @@ object Elements : TemplateGroupBase() {
} }
""" """
} }
specialFor(ArraysOfUnsigned) {
inlineOnly()
body { "return storage.single().to${primitive!!.name}()" }
}
} }
val f_singleOrNull = fn("singleOrNull()") { val f_singleOrNull = fn("singleOrNull()") {
includeDefault() includeDefault()
include(Lists, CharSequences) include(Lists, CharSequences, ArraysOfUnsigned)
} builder { } builder {
doc { "Returns single ${f.element}, or `null` if the ${f.collection} is empty or has more than one ${f.element}." } doc { "Returns single ${f.element}, or `null` if the ${f.collection} is empty or has more than one ${f.element}." }
returns("T?") returns("T?")
@@ -788,7 +810,7 @@ object Elements : TemplateGroupBase() {
return if (length == 1) this[0] else null return if (length == 1) this[0] else null
""" """
} }
body(Lists, ArraysOfObjects, ArraysOfPrimitives) { body(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
""" """
return if (size == 1) this[0] else null return if (size == 1) this[0] else null
""" """
@@ -797,11 +819,14 @@ object Elements : TemplateGroupBase() {
val f_single_predicate = fn("single(predicate: (T) -> Boolean)") { val f_single_predicate = fn("single(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(CharSequences) include(CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline() inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Returns the single ${f.element} matching the given [predicate], or throws exception if there is no or more than one matching ${f.element}." } doc { "Returns the single ${f.element} matching the given [predicate], or throws exception if there is no or more than one matching ${f.element}." }
returns("T") returns("T")
body { body {
""" """
var single: T? = null var single: T? = null
@@ -822,11 +847,14 @@ object Elements : TemplateGroupBase() {
val f_singleOrNull_predicate = fn("singleOrNull(predicate: (T) -> Boolean)") { val f_singleOrNull_predicate = fn("singleOrNull(predicate: (T) -> Boolean)") {
includeDefault() includeDefault()
include(CharSequences) include(CharSequences, ArraysOfUnsigned)
} builder { } builder {
inline() inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Returns the single ${f.element} matching the given [predicate], or `null` if ${f.element} was not found or more than one ${f.element} was found." } doc { "Returns the single ${f.element} matching the given [predicate], or `null` if ${f.element} was not found or more than one ${f.element} was found." }
returns("T?") returns("T?")
body { body {
""" """
var single: T? = null var single: T? = null
@@ -15,7 +15,7 @@ val Family.DocExtension.element: String
val Family.CodeExtension.size: String val Family.CodeExtension.size: String
get() = when (family) { get() = when (family) {
Iterables, Collections, Lists, Sets, Maps, InvariantArraysOfObjects, ArraysOfObjects, ArraysOfPrimitives -> "size" Iterables, Collections, Lists, Sets, Maps, InvariantArraysOfObjects, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned -> "size"
CharSequences, Strings -> "length" CharSequences, Strings -> "length"
else -> error("size property isn't supported for $family") else -> error("size property isn't supported for $family")
} }