Specialize Progression first/last/OrNull functions #KT-42178
This commit is contained in:
committed by
Space
parent
cca2680c7f
commit
42c9a27b8a
+20
@@ -4491,6 +4491,12 @@ public final class kotlin/ranges/RangesKt {
|
||||
public static final fun downTo (SI)Lkotlin/ranges/IntProgression;
|
||||
public static final fun downTo (SJ)Lkotlin/ranges/LongProgression;
|
||||
public static final fun downTo (SS)Lkotlin/ranges/IntProgression;
|
||||
public static final fun first (Lkotlin/ranges/CharProgression;)C
|
||||
public static final fun first (Lkotlin/ranges/IntProgression;)I
|
||||
public static final fun first (Lkotlin/ranges/LongProgression;)J
|
||||
public static final fun firstOrNull (Lkotlin/ranges/CharProgression;)Ljava/lang/Character;
|
||||
public static final fun firstOrNull (Lkotlin/ranges/IntProgression;)Ljava/lang/Integer;
|
||||
public static final fun firstOrNull (Lkotlin/ranges/LongProgression;)Ljava/lang/Long;
|
||||
public static final synthetic fun floatRangeContains (Lkotlin/ranges/ClosedRange;B)Z
|
||||
public static final fun floatRangeContains (Lkotlin/ranges/ClosedRange;D)Z
|
||||
public static final synthetic fun floatRangeContains (Lkotlin/ranges/ClosedRange;I)Z
|
||||
@@ -4501,6 +4507,12 @@ public final class kotlin/ranges/RangesKt {
|
||||
public static final synthetic fun intRangeContains (Lkotlin/ranges/ClosedRange;F)Z
|
||||
public static final fun intRangeContains (Lkotlin/ranges/ClosedRange;J)Z
|
||||
public static final fun intRangeContains (Lkotlin/ranges/ClosedRange;S)Z
|
||||
public static final fun last (Lkotlin/ranges/CharProgression;)C
|
||||
public static final fun last (Lkotlin/ranges/IntProgression;)I
|
||||
public static final fun last (Lkotlin/ranges/LongProgression;)J
|
||||
public static final fun lastOrNull (Lkotlin/ranges/CharProgression;)Ljava/lang/Character;
|
||||
public static final fun lastOrNull (Lkotlin/ranges/IntProgression;)Ljava/lang/Integer;
|
||||
public static final fun lastOrNull (Lkotlin/ranges/LongProgression;)Ljava/lang/Long;
|
||||
public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;B)Z
|
||||
public static final synthetic fun longRangeContains (Lkotlin/ranges/ClosedRange;D)Z
|
||||
public static final synthetic fun longRangeContains (Lkotlin/ranges/ClosedRange;F)Z
|
||||
@@ -4640,6 +4652,14 @@ public final class kotlin/ranges/URangesKt {
|
||||
public static final fun downTo-J1ME1BU (II)Lkotlin/ranges/UIntProgression;
|
||||
public static final fun downTo-Kr8caGY (BB)Lkotlin/ranges/UIntProgression;
|
||||
public static final fun downTo-eb3DHEI (JJ)Lkotlin/ranges/ULongProgression;
|
||||
public static final fun first (Lkotlin/ranges/UIntProgression;)I
|
||||
public static final fun first (Lkotlin/ranges/ULongProgression;)J
|
||||
public static final fun firstOrNull (Lkotlin/ranges/UIntProgression;)Lkotlin/UInt;
|
||||
public static final fun firstOrNull (Lkotlin/ranges/ULongProgression;)Lkotlin/ULong;
|
||||
public static final fun last (Lkotlin/ranges/UIntProgression;)I
|
||||
public static final fun last (Lkotlin/ranges/ULongProgression;)J
|
||||
public static final fun lastOrNull (Lkotlin/ranges/UIntProgression;)Lkotlin/UInt;
|
||||
public static final fun lastOrNull (Lkotlin/ranges/ULongProgression;)Lkotlin/ULong;
|
||||
public static final fun random (Lkotlin/ranges/UIntRange;Lkotlin/random/Random;)I
|
||||
public static final fun random (Lkotlin/ranges/ULongRange;Lkotlin/random/Random;)J
|
||||
public static final fun randomOrNull (Lkotlin/ranges/UIntRange;Lkotlin/random/Random;)Lkotlin/UInt;
|
||||
|
||||
@@ -26,6 +26,11 @@ object Elements : TemplateGroupBase() {
|
||||
sourceFile(SourceFile.URanges)
|
||||
}
|
||||
}
|
||||
specialFor(ProgressionsOfPrimitives) {
|
||||
if (primitive in PrimitiveType.unsignedPrimitives) {
|
||||
sourceFile(SourceFile.URanges)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,10 +448,13 @@ object Elements : TemplateGroupBase() {
|
||||
val f_first = fn("first()") {
|
||||
includeDefault()
|
||||
include(CharSequences, Lists, ArraysOfUnsigned)
|
||||
include(ProgressionsOfPrimitives, PrimitiveType.rangePrimitives)
|
||||
} builder {
|
||||
doc { """Returns first ${f.element}.
|
||||
@throws [NoSuchElementException] if the ${f.collection} is empty.
|
||||
""" }
|
||||
specialFor(ProgressionsOfPrimitives) {
|
||||
since("1.7")
|
||||
}
|
||||
doc { "Returns the first ${f.element}." }
|
||||
throws("NoSuchElementException", "if the ${f.collection} is empty.")
|
||||
returns("T")
|
||||
body {
|
||||
"""
|
||||
@@ -476,6 +484,13 @@ object Elements : TemplateGroupBase() {
|
||||
return iterator.next()
|
||||
"""
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Progression ${'$'}this is empty.")
|
||||
return this.first
|
||||
"""
|
||||
}
|
||||
|
||||
specialFor(ArraysOfUnsigned) {
|
||||
inlineOnly()
|
||||
@@ -486,7 +501,11 @@ object Elements : TemplateGroupBase() {
|
||||
val f_firstOrNull = fn("firstOrNull()") {
|
||||
includeDefault()
|
||||
include(CharSequences, Lists, ArraysOfUnsigned)
|
||||
include(ProgressionsOfPrimitives, PrimitiveType.rangePrimitives)
|
||||
} builder {
|
||||
specialFor(ProgressionsOfPrimitives) {
|
||||
since("1.7")
|
||||
}
|
||||
doc { "Returns the first ${f.element}, or `null` if the ${f.collection} is empty." }
|
||||
returns("T?")
|
||||
body {
|
||||
@@ -520,6 +539,11 @@ object Elements : TemplateGroupBase() {
|
||||
return iterator.next()
|
||||
"""
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"""
|
||||
return if (isEmpty()) null else this.first
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
val f_first_predicate = fn("first(predicate: (T) -> Boolean)") {
|
||||
@@ -578,7 +602,11 @@ object Elements : TemplateGroupBase() {
|
||||
val f_last = fn("last()") {
|
||||
includeDefault()
|
||||
include(CharSequences, Lists, ArraysOfUnsigned)
|
||||
include(ProgressionsOfPrimitives, PrimitiveType.rangePrimitives)
|
||||
} builder {
|
||||
specialFor(ProgressionsOfPrimitives) {
|
||||
since("1.7")
|
||||
}
|
||||
doc { "Returns the last ${f.element}." }
|
||||
throws("NoSuchElementException", "if the ${f.collection} is empty.")
|
||||
sample("${f.sampleClass}.last")
|
||||
@@ -617,6 +645,13 @@ object Elements : TemplateGroupBase() {
|
||||
return this[lastIndex]
|
||||
"""
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Progression ${'$'}this is empty.")
|
||||
return this.last
|
||||
"""
|
||||
}
|
||||
|
||||
specialFor(ArraysOfUnsigned) {
|
||||
inlineOnly()
|
||||
@@ -627,7 +662,11 @@ object Elements : TemplateGroupBase() {
|
||||
val f_lastOrNull = fn("lastOrNull()") {
|
||||
includeDefault()
|
||||
include(Lists, CharSequences, ArraysOfUnsigned)
|
||||
include(ProgressionsOfPrimitives, PrimitiveType.rangePrimitives)
|
||||
} builder {
|
||||
specialFor(ProgressionsOfPrimitives) {
|
||||
since("1.7")
|
||||
}
|
||||
doc { "Returns the last ${f.element}, or `null` if the ${f.collection} is empty." }
|
||||
sample("${f.sampleClass}.last")
|
||||
returns("T?")
|
||||
@@ -668,6 +707,11 @@ object Elements : TemplateGroupBase() {
|
||||
return if (isEmpty()) null else this[size - 1]
|
||||
"""
|
||||
}
|
||||
body(ProgressionsOfPrimitives) {
|
||||
"""
|
||||
return if (isEmpty()) null else this.last
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
val f_last_predicate = fn("last(predicate: (T) -> Boolean)") {
|
||||
|
||||
@@ -34,6 +34,7 @@ object DocExtensions {
|
||||
CharSequences -> "char sequence"
|
||||
ArraysOfObjects, ArraysOfPrimitives, InvariantArraysOfObjects, ArraysOfUnsigned -> "array"
|
||||
Ranges, RangesOfPrimitives -> "range"
|
||||
ProgressionsOfPrimitives -> "progression"
|
||||
Strings, Sequences, Maps, Lists, Sets -> name.singularize().decapitalize()
|
||||
else -> "collection"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user