diff --git a/libraries/stdlib/api/js-v1/kotlin.kt b/libraries/stdlib/api/js-v1/kotlin.kt index dd238f99f1e..b047facf102 100644 --- a/libraries/stdlib/api/js-v1/kotlin.kt +++ b/libraries/stdlib/api/js-v1/kotlin.kt @@ -3231,4 +3231,4 @@ public final annotation class UseExperimental : kotlin.Annotation { public constructor UseExperimental(vararg markerClass: kotlin.reflect.KClass) public final val markerClass: kotlin.Array> { get; } -} +} \ No newline at end of file diff --git a/libraries/stdlib/api/js-v1/kotlin.ranges.kt b/libraries/stdlib/api/js-v1/kotlin.ranges.kt index a1de3d05fc7..5ed5a69d989 100644 --- a/libraries/stdlib/api/js-v1/kotlin.ranges.kt +++ b/libraries/stdlib/api/js-v1/kotlin.ranges.kt @@ -327,6 +327,66 @@ public infix fun kotlin.ULong.downTo(to: kotlin.ULong): kotlin.ranges.ULongProgr @kotlin.WasExperimental(markerClass = {kotlin.ExperimentalUnsignedTypes::class}) public infix fun kotlin.UShort.downTo(to: kotlin.UShort): kotlin.ranges.UIntProgression +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.first(): kotlin.Char + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.first(): kotlin.Int + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.first(): kotlin.Long + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.first(): kotlin.UInt + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.first(): kotlin.ULong + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.firstOrNull(): kotlin.Char? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.firstOrNull(): kotlin.Int? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.firstOrNull(): kotlin.Long? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.firstOrNull(): kotlin.UInt? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.firstOrNull(): kotlin.ULong? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.last(): kotlin.Char + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.last(): kotlin.Int + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.last(): kotlin.Long + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.last(): kotlin.UInt + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.last(): kotlin.ULong + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.lastOrNull(): kotlin.Char? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.lastOrNull(): kotlin.Int? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.lastOrNull(): kotlin.Long? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.lastOrNull(): kotlin.UInt? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.lastOrNull(): kotlin.ULong? + @kotlin.SinceKotlin(version = "1.3") @kotlin.internal.InlineOnly public inline fun kotlin.ranges.CharRange.random(): kotlin.Char diff --git a/libraries/stdlib/api/js/kotlin.kt b/libraries/stdlib/api/js/kotlin.kt index 9e37dffe0db..752d66f1d04 100644 --- a/libraries/stdlib/api/js/kotlin.kt +++ b/libraries/stdlib/api/js/kotlin.kt @@ -3231,4 +3231,4 @@ public final annotation class UseExperimental : kotlin.Annotation { public constructor UseExperimental(vararg markerClass: kotlin.reflect.KClass) public final val markerClass: kotlin.Array> { get; } -} +} \ No newline at end of file diff --git a/libraries/stdlib/api/js/kotlin.ranges.kt b/libraries/stdlib/api/js/kotlin.ranges.kt index 771c9a2bae9..49e6f8b6363 100644 --- a/libraries/stdlib/api/js/kotlin.ranges.kt +++ b/libraries/stdlib/api/js/kotlin.ranges.kt @@ -327,6 +327,66 @@ public infix fun kotlin.ULong.downTo(to: kotlin.ULong): kotlin.ranges.ULongProgr @kotlin.WasExperimental(markerClass = {kotlin.ExperimentalUnsignedTypes::class}) public infix fun kotlin.UShort.downTo(to: kotlin.UShort): kotlin.ranges.UIntProgression +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.first(): kotlin.Char + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.first(): kotlin.Int + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.first(): kotlin.Long + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.first(): kotlin.UInt + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.first(): kotlin.ULong + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.firstOrNull(): kotlin.Char? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.firstOrNull(): kotlin.Int? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.firstOrNull(): kotlin.Long? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.firstOrNull(): kotlin.UInt? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.firstOrNull(): kotlin.ULong? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.last(): kotlin.Char + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.last(): kotlin.Int + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.last(): kotlin.Long + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.last(): kotlin.UInt + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.last(): kotlin.ULong + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.CharProgression.lastOrNull(): kotlin.Char? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.IntProgression.lastOrNull(): kotlin.Int? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.LongProgression.lastOrNull(): kotlin.Long? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.UIntProgression.lastOrNull(): kotlin.UInt? + +@kotlin.SinceKotlin(version = "1.7") +public fun kotlin.ranges.ULongProgression.lastOrNull(): kotlin.ULong? + @kotlin.SinceKotlin(version = "1.3") @kotlin.internal.InlineOnly public inline fun kotlin.ranges.CharRange.random(): kotlin.Char diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index ab2d3d14242..0ba540452f3 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -1005,8 +1005,9 @@ public inline fun CharArray.findLast(predicate: (Char) -> Boolean): Char? { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun Array.first(): T { if (isEmpty()) @@ -1015,8 +1016,9 @@ public fun Array.first(): T { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun ByteArray.first(): Byte { if (isEmpty()) @@ -1025,8 +1027,9 @@ public fun ByteArray.first(): Byte { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun ShortArray.first(): Short { if (isEmpty()) @@ -1035,8 +1038,9 @@ public fun ShortArray.first(): Short { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun IntArray.first(): Int { if (isEmpty()) @@ -1045,8 +1049,9 @@ public fun IntArray.first(): Int { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun LongArray.first(): Long { if (isEmpty()) @@ -1055,8 +1060,9 @@ public fun LongArray.first(): Long { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun FloatArray.first(): Float { if (isEmpty()) @@ -1065,8 +1071,9 @@ public fun FloatArray.first(): Float { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun DoubleArray.first(): Double { if (isEmpty()) @@ -1075,8 +1082,9 @@ public fun DoubleArray.first(): Double { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun BooleanArray.first(): Boolean { if (isEmpty()) @@ -1085,8 +1093,9 @@ public fun BooleanArray.first(): Boolean { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ public fun CharArray.first(): Char { if (isEmpty()) diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index e0613d1ddcc..02e04194720 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -188,8 +188,9 @@ public inline fun List.findLast(predicate: (T) -> Boolean): T? { } /** - * Returns first element. - * @throws [NoSuchElementException] if the collection is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the collection is empty. */ public fun Iterable.first(): T { when (this) { @@ -204,8 +205,9 @@ public fun Iterable.first(): T { } /** - * Returns first element. - * @throws [NoSuchElementException] if the list is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the list is empty. */ public fun List.first(): T { if (isEmpty()) diff --git a/libraries/stdlib/common/src/generated/_Ranges.kt b/libraries/stdlib/common/src/generated/_Ranges.kt index da3cdfa76ed..b1f2baaab8f 100644 --- a/libraries/stdlib/common/src/generated/_Ranges.kt +++ b/libraries/stdlib/common/src/generated/_Ranges.kt @@ -15,6 +15,138 @@ package kotlin.ranges import kotlin.random.* +/** + * Returns the first element. + * + * @throws NoSuchElementException if the progression is empty. + */ +@SinceKotlin("1.7") +public fun IntProgression.first(): Int { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.first +} + +/** + * Returns the first element. + * + * @throws NoSuchElementException if the progression is empty. + */ +@SinceKotlin("1.7") +public fun LongProgression.first(): Long { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.first +} + +/** + * Returns the first element. + * + * @throws NoSuchElementException if the progression is empty. + */ +@SinceKotlin("1.7") +public fun CharProgression.first(): Char { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.first +} + +/** + * Returns the first element, or `null` if the progression is empty. + */ +@SinceKotlin("1.7") +public fun IntProgression.firstOrNull(): Int? { + return if (isEmpty()) null else this.first +} + +/** + * Returns the first element, or `null` if the progression is empty. + */ +@SinceKotlin("1.7") +public fun LongProgression.firstOrNull(): Long? { + return if (isEmpty()) null else this.first +} + +/** + * Returns the first element, or `null` if the progression is empty. + */ +@SinceKotlin("1.7") +public fun CharProgression.firstOrNull(): Char? { + return if (isEmpty()) null else this.first +} + +/** + * Returns the last element. + * + * @throws NoSuchElementException if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun IntProgression.last(): Int { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.last +} + +/** + * Returns the last element. + * + * @throws NoSuchElementException if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun LongProgression.last(): Long { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.last +} + +/** + * Returns the last element. + * + * @throws NoSuchElementException if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun CharProgression.last(): Char { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.last +} + +/** + * Returns the last element, or `null` if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun IntProgression.lastOrNull(): Int? { + return if (isEmpty()) null else this.last +} + +/** + * Returns the last element, or `null` if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun LongProgression.lastOrNull(): Long? { + return if (isEmpty()) null else this.last +} + +/** + * Returns the last element, or `null` if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun CharProgression.lastOrNull(): Char? { + return if (isEmpty()) null else this.last +} + /** * Returns a random element from this range. * diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index b20b452b497..0cccad66dc4 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -100,10 +100,11 @@ public inline fun Sequence.findLast(predicate: (T) -> Boolean): T? { } /** - * Returns first element. - * @throws [NoSuchElementException] if the sequence is empty. + * Returns the first element. * * The operation is _terminal_. + * + * @throws NoSuchElementException if the sequence is empty. */ public fun Sequence.first(): T { val iterator = iterator() diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index b145d81f479..65809a1eee2 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -63,8 +63,9 @@ public inline fun CharSequence.findLast(predicate: (Char) -> Boolean): Char? { } /** - * Returns first character. - * @throws [NoSuchElementException] if the char sequence is empty. + * Returns the first character. + * + * @throws NoSuchElementException if the char sequence is empty. */ public fun CharSequence.first(): Char { if (isEmpty()) diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index bf5e8079b55..35f23c59d45 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -507,8 +507,9 @@ public inline fun UShortArray.findLast(predicate: (UShort) -> Boolean): UShort? } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -518,8 +519,9 @@ public inline fun UIntArray.first(): UInt { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -529,8 +531,9 @@ public inline fun ULongArray.first(): ULong { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes @@ -540,8 +543,9 @@ public inline fun UByteArray.first(): UByte { } /** - * Returns first element. - * @throws [NoSuchElementException] if the array is empty. + * Returns the first element. + * + * @throws NoSuchElementException if the array is empty. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes diff --git a/libraries/stdlib/common/src/generated/_URanges.kt b/libraries/stdlib/common/src/generated/_URanges.kt index eb6d5b4498c..b432e514a5d 100644 --- a/libraries/stdlib/common/src/generated/_URanges.kt +++ b/libraries/stdlib/common/src/generated/_URanges.kt @@ -15,6 +15,94 @@ package kotlin.ranges import kotlin.random.* +/** + * Returns the first element. + * + * @throws NoSuchElementException if the progression is empty. + */ +@SinceKotlin("1.7") +public fun UIntProgression.first(): UInt { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.first +} + +/** + * Returns the first element. + * + * @throws NoSuchElementException if the progression is empty. + */ +@SinceKotlin("1.7") +public fun ULongProgression.first(): ULong { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.first +} + +/** + * Returns the first element, or `null` if the progression is empty. + */ +@SinceKotlin("1.7") +public fun UIntProgression.firstOrNull(): UInt? { + return if (isEmpty()) null else this.first +} + +/** + * Returns the first element, or `null` if the progression is empty. + */ +@SinceKotlin("1.7") +public fun ULongProgression.firstOrNull(): ULong? { + return if (isEmpty()) null else this.first +} + +/** + * Returns the last element. + * + * @throws NoSuchElementException if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun UIntProgression.last(): UInt { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.last +} + +/** + * Returns the last element. + * + * @throws NoSuchElementException if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun ULongProgression.last(): ULong { + if (isEmpty()) + throw NoSuchElementException("Progression $this is empty.") + return this.last +} + +/** + * Returns the last element, or `null` if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun UIntProgression.lastOrNull(): UInt? { + return if (isEmpty()) null else this.last +} + +/** + * Returns the last element, or `null` if the progression is empty. + * + * @sample samples.collections.Collections.Elements.last + */ +@SinceKotlin("1.7") +public fun ULongProgression.lastOrNull(): ULong? { + return if (isEmpty()) null else this.last +} + /** * Returns a random element from this range. * diff --git a/libraries/stdlib/test/ranges/RangeTest.kt b/libraries/stdlib/test/ranges/RangeTest.kt index 58bd815be9a..112b39b9ca4 100644 --- a/libraries/stdlib/test/ranges/RangeTest.kt +++ b/libraries/stdlib/test/ranges/RangeTest.kt @@ -399,4 +399,32 @@ public class RangeTest { assertNull(LongRange.EMPTY.randomOrNull()) assertNull(CharRange.EMPTY.randomOrNull()) } + + @Test fun firstInEmptyRange() { + assertFailsWith { IntRange.EMPTY.first() } + assertFailsWith { LongRange.EMPTY.first() } + assertFailsWith { CharRange.EMPTY.first() } + assertFailsWith { IntProgression.fromClosedRange(0, 3, -2).first() } + } + + @Test fun firstOrNullInEmptyRange() { + assertNull(IntRange.EMPTY.firstOrNull()) + assertNull(LongRange.EMPTY.firstOrNull()) + assertNull(CharRange.EMPTY.firstOrNull()) + assertNull(IntProgression.fromClosedRange(0, 3, -2).firstOrNull()) + } + + @Test fun lastInEmptyRange() { + assertFailsWith { IntRange.EMPTY.last() } + assertFailsWith { LongRange.EMPTY.last() } + assertFailsWith { CharRange.EMPTY.last() } + assertFailsWith { IntProgression.fromClosedRange(0, 3, -2).last() } + } + + @Test fun lastOrNullInEmptyRange() { + assertNull(IntRange.EMPTY.lastOrNull()) + assertNull(LongRange.EMPTY.lastOrNull()) + assertNull(CharRange.EMPTY.lastOrNull()) + assertNull(IntProgression.fromClosedRange(0, 3, -2).lastOrNull()) + } } diff --git a/libraries/stdlib/test/ranges/URangeTest.kt b/libraries/stdlib/test/ranges/URangeTest.kt index 7ed7ce8fb31..93bb4a7fbfe 100644 --- a/libraries/stdlib/test/ranges/URangeTest.kt +++ b/libraries/stdlib/test/ranges/URangeTest.kt @@ -241,4 +241,28 @@ public class URangeTest { assertFailsWith { UIntRange.EMPTY.random() } assertFailsWith { ULongRange.EMPTY.random() } } + + @Test fun firstInEmptyRange() { + assertFailsWith { UIntRange.EMPTY.first() } + assertFailsWith { ULongRange.EMPTY.first() } + assertFailsWith { UIntProgression.fromClosedRange(0u, 3u, -2).first() } + } + + @Test fun firstOrNullInEmptyRange() { + assertNull(UIntRange.EMPTY.firstOrNull()) + assertNull(ULongRange.EMPTY.firstOrNull()) + assertNull(UIntProgression.fromClosedRange(0u, 3u, -2).firstOrNull()) + } + + @Test fun lastInEmptyRange() { + assertFailsWith { UIntRange.EMPTY.last() } + assertFailsWith { ULongRange.EMPTY.last() } + assertFailsWith { UIntProgression.fromClosedRange(0u, 3u, -2).last() } + } + + @Test fun lastOrNullInEmptyRange() { + assertNull(UIntRange.EMPTY.lastOrNull()) + assertNull(ULongRange.EMPTY.lastOrNull()) + assertNull(UIntProgression.fromClosedRange(0u, 3u, -2).lastOrNull()) + } } diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index 563293fce54..a3b3d499c7a 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -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; diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index d4ecee50749..225b8913a1e 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -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)") { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/FamilyProperties.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/FamilyProperties.kt index 88dd81fa030..d08020c68a6 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/FamilyProperties.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/dsl/FamilyProperties.kt @@ -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" }