Implement first, last & single extension functions for UArrays
This commit is contained in:
committed by
Ilya Gorbunov
parent
299fac8e2d
commit
92cd84682c
File diff suppressed because it is too large
Load Diff
@@ -17,9 +17,9 @@ package kotlin.collections
|
|||||||
/**
|
/**
|
||||||
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
||||||
* The array is expected to be sorted, otherwise the result is undefined.
|
* The array is expected to be sorted, otherwise the result is undefined.
|
||||||
*
|
*
|
||||||
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
||||||
*
|
*
|
||||||
* @return the index of the element, if it is contained in the array within the specified range;
|
* @return the index of the element, if it is contained in the array within the specified range;
|
||||||
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
||||||
* The insertion point is defined as the index at which the element should be inserted,
|
* The insertion point is defined as the index at which the element should be inserted,
|
||||||
@@ -49,9 +49,9 @@ public fun UIntArray.binarySearch(element: UInt, fromIndex: Int = 0, toIndex: In
|
|||||||
/**
|
/**
|
||||||
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
||||||
* The array is expected to be sorted, otherwise the result is undefined.
|
* The array is expected to be sorted, otherwise the result is undefined.
|
||||||
*
|
*
|
||||||
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
||||||
*
|
*
|
||||||
* @return the index of the element, if it is contained in the array within the specified range;
|
* @return the index of the element, if it is contained in the array within the specified range;
|
||||||
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
||||||
* The insertion point is defined as the index at which the element should be inserted,
|
* The insertion point is defined as the index at which the element should be inserted,
|
||||||
@@ -81,9 +81,9 @@ public fun ULongArray.binarySearch(element: ULong, fromIndex: Int = 0, toIndex:
|
|||||||
/**
|
/**
|
||||||
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
||||||
* The array is expected to be sorted, otherwise the result is undefined.
|
* The array is expected to be sorted, otherwise the result is undefined.
|
||||||
*
|
*
|
||||||
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
||||||
*
|
*
|
||||||
* @return the index of the element, if it is contained in the array within the specified range;
|
* @return the index of the element, if it is contained in the array within the specified range;
|
||||||
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
||||||
* The insertion point is defined as the index at which the element should be inserted,
|
* The insertion point is defined as the index at which the element should be inserted,
|
||||||
@@ -113,9 +113,9 @@ public fun UByteArray.binarySearch(element: UByte, fromIndex: Int = 0, toIndex:
|
|||||||
/**
|
/**
|
||||||
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
* Searches the array or the range of the array for the provided [element] using the binary search algorithm.
|
||||||
* The array is expected to be sorted, otherwise the result is undefined.
|
* The array is expected to be sorted, otherwise the result is undefined.
|
||||||
*
|
*
|
||||||
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
* If the array contains multiple elements equal to the specified [element], there is no guarantee which one will be found.
|
||||||
*
|
*
|
||||||
* @return the index of the element, if it is contained in the array within the specified range;
|
* @return the index of the element, if it is contained in the array within the specified range;
|
||||||
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
* otherwise, the inverted insertion point `(-insertion point - 1)`.
|
||||||
* The insertion point is defined as the index at which the element should be inserted,
|
* The insertion point is defined as the index at which the element should be inserted,
|
||||||
@@ -176,4 +176,5 @@ public fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = si
|
|||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
@@ -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")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user