Implement reduce, forEach, min & max extension functions for UArrays
This commit is contained in:
committed by
Ilya Gorbunov
parent
fc85781bfc
commit
690e35f11a
+24
@@ -2323,6 +2323,14 @@ public final class kotlin/collections/UArraysKt {
|
||||
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 getIndices--ajY-9A ([I)Lkotlin/ranges/IntRange;
|
||||
public static final fun getIndices-GBYM_sE ([B)Lkotlin/ranges/IntRange;
|
||||
public static final fun getIndices-QwZRm1k ([J)Lkotlin/ranges/IntRange;
|
||||
public static final fun getIndices-rL5Bavg ([S)Lkotlin/ranges/IntRange;
|
||||
public static final fun getLastIndex--ajY-9A ([I)I
|
||||
public static final fun getLastIndex-GBYM_sE ([B)I
|
||||
public static final fun getLastIndex-QwZRm1k ([J)I
|
||||
public static final fun getLastIndex-rL5Bavg ([S)I
|
||||
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;
|
||||
@@ -2331,6 +2339,22 @@ public final class kotlin/collections/UArraysKt {
|
||||
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 max--ajY-9A ([I)Lkotlin/UInt;
|
||||
public static final fun max-GBYM_sE ([B)Lkotlin/UByte;
|
||||
public static final fun max-QwZRm1k ([J)Lkotlin/ULong;
|
||||
public static final fun max-rL5Bavg ([S)Lkotlin/UShort;
|
||||
public static final fun maxWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
|
||||
public static final fun maxWith-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
|
||||
public static final fun maxWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
|
||||
public static final fun maxWith-zrEWJaI ([JLjava/util/Comparator;)Lkotlin/ULong;
|
||||
public static final fun min--ajY-9A ([I)Lkotlin/UInt;
|
||||
public static final fun min-GBYM_sE ([B)Lkotlin/UByte;
|
||||
public static final fun min-QwZRm1k ([J)Lkotlin/ULong;
|
||||
public static final fun min-rL5Bavg ([S)Lkotlin/UShort;
|
||||
public static final fun minWith-XMRcp5o ([BLjava/util/Comparator;)Lkotlin/UByte;
|
||||
public static final fun minWith-YmdZ_VM ([ILjava/util/Comparator;)Lkotlin/UInt;
|
||||
public static final fun minWith-eOHTfZs ([SLjava/util/Comparator;)Lkotlin/UShort;
|
||||
public static final fun minWith-zrEWJaI ([JLjava/util/Comparator;)Lkotlin/ULong;
|
||||
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-ojwP5H8 ([SLjava/util/Collection;)[S
|
||||
|
||||
@@ -276,6 +276,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
include(Sequences, genericSpecializations)
|
||||
include(ArraysOfObjects, genericSpecializations)
|
||||
include(ArraysOfPrimitives, PrimitiveType.defaultPrimitives - PrimitiveType.Boolean)
|
||||
include(ArraysOfUnsigned)
|
||||
include(CharSequences)
|
||||
} builder {
|
||||
val isFloat = primitive?.isFloatingPoint() == true
|
||||
@@ -307,7 +308,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
return $op
|
||||
"""
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives, CharSequences) {
|
||||
body(ArraysOfObjects, ArraysOfPrimitives, CharSequences, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
var $op = this[0]
|
||||
@@ -330,9 +331,11 @@ object Aggregates : TemplateGroupBase() {
|
||||
|
||||
val f_minBy = fn("minBy(selector: (T) -> R)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences)
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { "Returns the first ${f.element} yielding the smallest value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
||||
sample("samples.collections.Collections.Aggregates.minBy")
|
||||
typeParam("R : Comparable<R>")
|
||||
@@ -355,7 +358,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
return minElem
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
|
||||
@@ -379,7 +382,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
|
||||
val f_minWith = fn("minWith(comparator: Comparator<in T>)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences)
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns the first ${f.element} having the smallest value according to the provided [comparator] or `null` if there are no ${f.element.pluralize()}." }
|
||||
returns("T?")
|
||||
@@ -396,7 +399,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
return min
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
var min = this[0]
|
||||
@@ -412,9 +415,10 @@ object Aggregates : TemplateGroupBase() {
|
||||
|
||||
val f_maxBy = fn("maxBy(selector: (T) -> R)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences)
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { "Returns the first ${f.element} yielding the largest value of the given function or `null` if there are no ${f.element.pluralize()}." }
|
||||
sample("samples.collections.Collections.Aggregates.maxBy")
|
||||
@@ -438,7 +442,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
return maxElem
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
|
||||
@@ -463,7 +467,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
|
||||
val f_maxWith = fn("maxWith(comparator: Comparator<in T>)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences)
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns the first ${f.element} having the largest value according to the provided [comparator] or `null` if there are no ${f.element.pluralize()}." }
|
||||
returns("T?")
|
||||
@@ -480,7 +484,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
return max
|
||||
"""
|
||||
}
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return null
|
||||
|
||||
@@ -614,9 +618,10 @@ object Aggregates : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_reduceIndexed = fn("reduceIndexed(operation: (index: Int, acc: T, T) -> T)") {
|
||||
include(ArraysOfPrimitives, CharSequences)
|
||||
include(ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc {
|
||||
"""
|
||||
@@ -686,9 +691,10 @@ object Aggregates : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_reduceRightIndexed = fn("reduceRightIndexed(operation: (index: Int, T, acc: T) -> T)") {
|
||||
include(CharSequences, ArraysOfPrimitives)
|
||||
include(CharSequences, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc {
|
||||
"""
|
||||
@@ -763,9 +769,10 @@ object Aggregates : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_reduce = fn("reduce(operation: (acc: T, T) -> T)") {
|
||||
include(ArraysOfPrimitives, CharSequences)
|
||||
include(ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { "Accumulates value starting with the first ${f.element} and applying [operation] from left to right to current accumulator value and each ${f.element}." }
|
||||
returns("T")
|
||||
@@ -819,9 +826,10 @@ object Aggregates : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_reduceRight = fn("reduceRight(operation: (T, acc: T) -> T)") {
|
||||
include(CharSequences, ArraysOfPrimitives)
|
||||
include(CharSequences, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { "Accumulates value starting with last ${f.element} and applying [operation] from right to left to each ${f.element} and current accumulator value." }
|
||||
returns("T")
|
||||
@@ -885,7 +893,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
specialFor(Iterables, Maps, CharSequences) {
|
||||
inline()
|
||||
doc { "Performs the given [action] on each ${f.element} and returns the ${f.collection} itself afterwards." }
|
||||
val collectionType = when(f) {
|
||||
val collectionType = when (f) {
|
||||
Maps -> "M"
|
||||
CharSequences -> "S"
|
||||
else -> "C"
|
||||
@@ -914,9 +922,10 @@ object Aggregates : TemplateGroupBase() {
|
||||
|
||||
val f_forEach = fn("forEach(action: (T) -> Unit)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences)
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { "Performs the given [action] on each ${f.element}." }
|
||||
specialFor(Iterables, Maps) { annotation("@kotlin.internal.HidesMembers") }
|
||||
@@ -930,9 +939,11 @@ object Aggregates : TemplateGroupBase() {
|
||||
|
||||
val f_forEachIndexed = fn("forEachIndexed(action: (index: Int, T) -> Unit)") {
|
||||
includeDefault()
|
||||
include(CharSequences)
|
||||
include(CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc {
|
||||
"""
|
||||
Performs the given [action] on each ${f.element}, providing sequential index with the ${f.element}.
|
||||
|
||||
@@ -52,7 +52,12 @@ object ArrayOps : TemplateGroupBase() {
|
||||
"get() = size - 1"
|
||||
}
|
||||
specialFor(ArraysOfUnsigned) {
|
||||
inlineOnly()
|
||||
// TODO: Make inlineOnly after KT-30185 is fixed.
|
||||
// InlineOnly properties currently are not inlined and may lead to IllegalAccessException
|
||||
// when accessed from an inline (or inlineOnly) method.
|
||||
// It is because the method body contains access call to inlineOnly property in nonpublic multifile part,
|
||||
// which may be inaccessible from method call site, where method body gets inlined.
|
||||
inline()
|
||||
body { "get() = storage.lastIndex" }
|
||||
}
|
||||
}
|
||||
@@ -66,7 +71,12 @@ object ArrayOps : TemplateGroupBase() {
|
||||
"get() = IntRange(0, lastIndex)"
|
||||
}
|
||||
specialFor(ArraysOfUnsigned) {
|
||||
inlineOnly()
|
||||
// TODO: Make inlineOnly after KT-30185 is fixed.
|
||||
// InlineOnly properties currently are not inlined and may lead to IllegalAccessException
|
||||
// when accessed from an inline (or inlineOnly) method.
|
||||
// It is because the method body contains access call to inlineOnly property in nonpublic multifile part,
|
||||
// which may be inaccessible from method call site, where method body gets inlined.
|
||||
inline()
|
||||
body { "get() = storage.indices" }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user