diff --git a/js/js.libraries/src/core/generated/_ArraysJs.kt b/js/js.libraries/src/core/generated/_ArraysJs.kt index 8e95a9efe15..906e0815cb7 100644 --- a/js/js.libraries/src/core/generated/_ArraysJs.kt +++ b/js/js.libraries/src/core/generated/_ArraysJs.kt @@ -2524,6 +2524,8 @@ public inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): Char? { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun Array.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2532,6 +2534,8 @@ public fun Array.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ByteArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2540,6 +2544,8 @@ public fun ByteArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ShortArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2548,6 +2554,8 @@ public fun ShortArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun IntArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2556,6 +2564,8 @@ public fun IntArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun LongArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2564,6 +2574,8 @@ public fun LongArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun FloatArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2572,6 +2584,8 @@ public fun FloatArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun DoubleArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2580,6 +2594,8 @@ public fun DoubleArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun BooleanArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2588,6 +2604,8 @@ public fun BooleanArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun CharArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2596,6 +2614,8 @@ public fun CharArray.drop(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun Array.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2604,6 +2624,8 @@ public fun Array.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ByteArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2612,6 +2634,8 @@ public fun ByteArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ShortArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2620,6 +2644,8 @@ public fun ShortArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun IntArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2628,6 +2654,8 @@ public fun IntArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun LongArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2636,6 +2664,8 @@ public fun LongArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun FloatArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2644,6 +2674,8 @@ public fun FloatArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun DoubleArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2652,6 +2684,8 @@ public fun DoubleArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun BooleanArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2660,6 +2694,8 @@ public fun BooleanArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun CharArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2668,6 +2704,8 @@ public fun CharArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun Array.dropLastWhile(predicate: (T) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2680,6 +2718,8 @@ public inline fun Array.dropLastWhile(predicate: (T) -> Boolean): Lis /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2692,6 +2732,8 @@ public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -2704,6 +2746,8 @@ public inline fun ShortArray.dropLastWhile(predicate: (Short) -> Boolean): List< /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2716,6 +2760,8 @@ public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2728,6 +2774,8 @@ public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -2740,6 +2788,8 @@ public inline fun FloatArray.dropLastWhile(predicate: (Float) -> Boolean): List< /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun DoubleArray.dropLastWhile(predicate: (Double) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2752,6 +2802,8 @@ public inline fun DoubleArray.dropLastWhile(predicate: (Double) -> Boolean): Lis /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun BooleanArray.dropLastWhile(predicate: (Boolean) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2764,6 +2816,8 @@ public inline fun BooleanArray.dropLastWhile(predicate: (Boolean) -> Boolean): L /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2776,6 +2830,8 @@ public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List Array.dropWhile(predicate: (T) -> Boolean): List { var yielding = false @@ -2792,6 +2848,8 @@ public inline fun Array.dropWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List { var yielding = false @@ -2808,6 +2866,8 @@ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List { var yielding = false @@ -2824,6 +2884,8 @@ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List Boolean): List { var yielding = false @@ -2840,6 +2902,8 @@ public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List { /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List { var yielding = false @@ -2856,6 +2920,8 @@ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List { var yielding = false @@ -2872,6 +2938,8 @@ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List Boolean): List { var yielding = false @@ -2888,6 +2956,8 @@ public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List Boolean): List { var yielding = false @@ -2904,6 +2974,8 @@ public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List< /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun CharArray.dropWhile(predicate: (Char) -> Boolean): List { var yielding = false @@ -3778,6 +3850,8 @@ public fun CharArray.sliceArray(indices: IntRange): CharArray { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun Array.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3796,6 +3870,8 @@ public fun Array.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ByteArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3814,6 +3890,8 @@ public fun ByteArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ShortArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3832,6 +3910,8 @@ public fun ShortArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun IntArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3850,6 +3930,8 @@ public fun IntArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun LongArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3868,6 +3950,8 @@ public fun LongArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun FloatArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3886,6 +3970,8 @@ public fun FloatArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun DoubleArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3904,6 +3990,8 @@ public fun DoubleArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun BooleanArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3922,6 +4010,8 @@ public fun BooleanArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun CharArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3940,6 +4030,8 @@ public fun CharArray.take(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun Array.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3955,6 +4047,8 @@ public fun Array.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ByteArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3970,6 +4064,8 @@ public fun ByteArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ShortArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3985,6 +4081,8 @@ public fun ShortArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun IntArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4000,6 +4098,8 @@ public fun IntArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun LongArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4015,6 +4115,8 @@ public fun LongArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun FloatArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4030,6 +4132,8 @@ public fun FloatArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun DoubleArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4045,6 +4149,8 @@ public fun DoubleArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun BooleanArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4060,6 +4166,8 @@ public fun BooleanArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun CharArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4075,6 +4183,8 @@ public fun CharArray.takeLast(n: Int): List { /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun Array.takeLastWhile(predicate: (T) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4087,6 +4197,8 @@ public inline fun Array.takeLastWhile(predicate: (T) -> Boolean): Lis /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4099,6 +4211,8 @@ public inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -4111,6 +4225,8 @@ public inline fun ShortArray.takeLastWhile(predicate: (Short) -> Boolean): List< /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4123,6 +4239,8 @@ public inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4135,6 +4253,8 @@ public inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -4147,6 +4267,8 @@ public inline fun FloatArray.takeLastWhile(predicate: (Float) -> Boolean): List< /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun DoubleArray.takeLastWhile(predicate: (Double) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4159,6 +4281,8 @@ public inline fun DoubleArray.takeLastWhile(predicate: (Double) -> Boolean): Lis /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun BooleanArray.takeLastWhile(predicate: (Boolean) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4171,6 +4295,8 @@ public inline fun BooleanArray.takeLastWhile(predicate: (Boolean) -> Boolean): L /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4183,6 +4309,8 @@ public inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List Array.takeWhile(predicate: (T) -> Boolean): List { val list = ArrayList() @@ -4196,6 +4324,8 @@ public inline fun Array.takeWhile(predicate: (T) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List { val list = ArrayList() @@ -4209,6 +4339,8 @@ public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List { val list = ArrayList() @@ -4222,6 +4354,8 @@ public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List Boolean): List { val list = ArrayList() @@ -4235,6 +4369,8 @@ public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List { /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List { val list = ArrayList() @@ -4248,6 +4384,8 @@ public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List { val list = ArrayList() @@ -4261,6 +4399,8 @@ public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List Boolean): List { val list = ArrayList() @@ -4274,6 +4414,8 @@ public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List Boolean): List { val list = ArrayList() @@ -4287,6 +4429,8 @@ public inline fun BooleanArray.takeWhile(predicate: (Boolean) -> Boolean): List< /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun CharArray.takeWhile(predicate: (Char) -> Boolean): List { val list = ArrayList() diff --git a/js/js.libraries/src/core/generated/_CollectionsJs.kt b/js/js.libraries/src/core/generated/_CollectionsJs.kt index c4c4581b433..fc8bcdff41e 100644 --- a/js/js.libraries/src/core/generated/_CollectionsJs.kt +++ b/js/js.libraries/src/core/generated/_CollectionsJs.kt @@ -537,6 +537,8 @@ public inline fun Iterable.singleOrNull(predicate: (T) -> Boolean): T? { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun Iterable.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -572,6 +574,8 @@ public fun Iterable.drop(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun List.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -580,6 +584,8 @@ public fun List.dropLast(n: Int): List { /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun List.dropLastWhile(predicate: (T) -> Boolean): List { if (!isEmpty()) { @@ -595,6 +601,8 @@ public inline fun List.dropLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun Iterable.dropWhile(predicate: (T) -> Boolean): List { var yielding = false @@ -713,6 +721,8 @@ public fun List.slice(indices: Iterable): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun Iterable.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -733,6 +743,8 @@ public fun Iterable.take(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun List.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -753,6 +765,8 @@ public fun List.takeLast(n: Int): List { /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun List.takeLastWhile(predicate: (T) -> Boolean): List { if (isEmpty()) @@ -774,6 +788,8 @@ public inline fun List.takeLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun Iterable.takeWhile(predicate: (T) -> Boolean): List { val list = ArrayList() diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 9d373d6adc2..df3bd2b786b 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -1452,181 +1452,253 @@ public expect inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): C /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun Array.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun ByteArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun ShortArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun IntArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun LongArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun FloatArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun DoubleArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun BooleanArray.drop(n: Int): List /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun CharArray.drop(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun Array.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun ByteArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun ShortArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun IntArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun LongArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun FloatArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun DoubleArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun BooleanArray.dropLast(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun CharArray.dropLast(n: Int): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun Array.dropLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun ShortArray.dropLastWhile(predicate: (Short) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun FloatArray.dropLastWhile(predicate: (Float) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun DoubleArray.dropLastWhile(predicate: (Double) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun BooleanArray.dropLastWhile(predicate: (Boolean) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun Array.dropWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun CharArray.dropWhile(predicate: (Char) -> Boolean): List @@ -2138,181 +2210,253 @@ public expect fun CharArray.sliceArray(indices: IntRange): CharArray /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun Array.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun ByteArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun ShortArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun IntArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun LongArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun FloatArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun DoubleArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun BooleanArray.take(n: Int): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun CharArray.take(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun Array.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun ByteArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun ShortArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun IntArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun LongArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun FloatArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun DoubleArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun BooleanArray.takeLast(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun CharArray.takeLast(n: Int): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun Array.takeLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun ShortArray.takeLastWhile(predicate: (Short) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun FloatArray.takeLastWhile(predicate: (Float) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun DoubleArray.takeLastWhile(predicate: (Double) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun BooleanArray.takeLastWhile(predicate: (Boolean) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun Array.takeWhile(predicate: (T) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun BooleanArray.takeWhile(predicate: (Boolean) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun CharArray.takeWhile(predicate: (Char) -> Boolean): List diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index 488ea26ef23..0df91881992 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -258,21 +258,29 @@ public expect inline fun Iterable.singleOrNull(predicate: (T) -> Boolean) /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun Iterable.drop(n: Int): List /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect fun List.dropLast(n: Int): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun List.dropLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public expect inline fun Iterable.dropWhile(predicate: (T) -> Boolean): List @@ -342,21 +350,29 @@ public expect fun List.slice(indices: Iterable): List /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun Iterable.take(n: Int): List /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public expect fun List.takeLast(n: Int): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun List.takeLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public expect inline fun Iterable.takeWhile(predicate: (T) -> Boolean): List diff --git a/libraries/stdlib/samples/test/samples/collections/collections.kt b/libraries/stdlib/samples/test/samples/collections/collections.kt index c7654bbbb28..f9b62280762 100644 --- a/libraries/stdlib/samples/test/samples/collections/collections.kt +++ b/libraries/stdlib/samples/test/samples/collections/collections.kt @@ -316,12 +316,12 @@ class Collections { val sb = StringBuilder("An existing string and a list: ") val numbers = listOf(1, 2, 3) assertPrints(numbers.joinTo(sb, prefix = "[", postfix = "]").toString(), "An existing string and a list: [1, 2, 3]") - + val lotOfNumbers: Iterable = 1..100 val firstNumbers = StringBuilder("First five numbers: ") assertPrints(lotOfNumbers.joinTo(firstNumbers, limit = 5).toString(), "First five numbers: 1, 2, 3, 4, 5, ...") } - + @Sample fun joinToString() { val numbers = listOf(1, 2, 3, 4, 5, 6) @@ -333,6 +333,24 @@ class Collections { assertPrints(chars.joinToString(limit = 5, truncated = "...!") { it.toUpperCase().toString() }, "A, B, C, D, E, ...!") } + @Sample + fun take() { + val chars = ('a'..'z').toList() + assertPrints(chars.take(3), "[a, b, c]") + assertPrints(chars.takeWhile { it < 'f' }, "[a, b, c, d, e]") + assertPrints(chars.takeLast(2), "[y, z]") + assertPrints(chars.takeLastWhile { it > 'w' }, "[x, y, z]") + } + + @Sample + fun drop() { + val chars = ('a'..'z').toList() + assertPrints(chars.drop(23), "[x, y, z]") + assertPrints(chars.dropLast(23), "[a, b, c]") + assertPrints(chars.dropWhile { it < 'x' }, "[x, y, z]") + assertPrints(chars.dropLastWhile { it > 'c' }, "[a, b, c]") + } + @Sample fun chunked() { val words = "one two three four five six seven eight nine ten".split(' ') @@ -341,7 +359,6 @@ class Collections { assertPrints(chunks, "[[one, two, three], [four, five, six], [seven, eight, nine], [ten]]") } - @Sample fun zipWithNext() { val letters = ('a'..'f').toList() diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index bc843d872ae..a19588af79e 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -2522,6 +2522,8 @@ public inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): Char? { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun Array.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2530,6 +2532,8 @@ public fun Array.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ByteArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2538,6 +2542,8 @@ public fun ByteArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ShortArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2546,6 +2552,8 @@ public fun ShortArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun IntArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2554,6 +2562,8 @@ public fun IntArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun LongArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2562,6 +2572,8 @@ public fun LongArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun FloatArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2570,6 +2582,8 @@ public fun FloatArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun DoubleArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2578,6 +2592,8 @@ public fun DoubleArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun BooleanArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2586,6 +2602,8 @@ public fun BooleanArray.drop(n: Int): List { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun CharArray.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2594,6 +2612,8 @@ public fun CharArray.drop(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun Array.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2602,6 +2622,8 @@ public fun Array.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ByteArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2610,6 +2632,8 @@ public fun ByteArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun ShortArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2618,6 +2642,8 @@ public fun ShortArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun IntArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2626,6 +2652,8 @@ public fun IntArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun LongArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2634,6 +2662,8 @@ public fun LongArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun FloatArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2642,6 +2672,8 @@ public fun FloatArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun DoubleArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2650,6 +2682,8 @@ public fun DoubleArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun BooleanArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2658,6 +2692,8 @@ public fun BooleanArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun CharArray.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -2666,6 +2702,8 @@ public fun CharArray.dropLast(n: Int): List { /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun Array.dropLastWhile(predicate: (T) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2678,6 +2716,8 @@ public inline fun Array.dropLastWhile(predicate: (T) -> Boolean): Lis /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2690,6 +2730,8 @@ public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -2702,6 +2744,8 @@ public inline fun ShortArray.dropLastWhile(predicate: (Short) -> Boolean): List< /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2714,6 +2758,8 @@ public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2726,6 +2772,8 @@ public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -2738,6 +2786,8 @@ public inline fun FloatArray.dropLastWhile(predicate: (Float) -> Boolean): List< /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun DoubleArray.dropLastWhile(predicate: (Double) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2750,6 +2800,8 @@ public inline fun DoubleArray.dropLastWhile(predicate: (Double) -> Boolean): Lis /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun BooleanArray.dropLastWhile(predicate: (Boolean) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2762,6 +2814,8 @@ public inline fun BooleanArray.dropLastWhile(predicate: (Boolean) -> Boolean): L /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -2774,6 +2828,8 @@ public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List Array.dropWhile(predicate: (T) -> Boolean): List { var yielding = false @@ -2790,6 +2846,8 @@ public inline fun Array.dropWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List { var yielding = false @@ -2806,6 +2864,8 @@ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List { var yielding = false @@ -2822,6 +2882,8 @@ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List Boolean): List { var yielding = false @@ -2838,6 +2900,8 @@ public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List { /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List { var yielding = false @@ -2854,6 +2918,8 @@ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List { var yielding = false @@ -2870,6 +2936,8 @@ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List Boolean): List { var yielding = false @@ -2886,6 +2954,8 @@ public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List Boolean): List { var yielding = false @@ -2902,6 +2972,8 @@ public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List< /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun CharArray.dropWhile(predicate: (Char) -> Boolean): List { var yielding = false @@ -3792,6 +3864,8 @@ public fun CharArray.sliceArray(indices: IntRange): CharArray { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun Array.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3810,6 +3884,8 @@ public fun Array.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ByteArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3828,6 +3904,8 @@ public fun ByteArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ShortArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3846,6 +3924,8 @@ public fun ShortArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun IntArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3864,6 +3944,8 @@ public fun IntArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun LongArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3882,6 +3964,8 @@ public fun LongArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun FloatArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3900,6 +3984,8 @@ public fun FloatArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun DoubleArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3918,6 +4004,8 @@ public fun DoubleArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun BooleanArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3936,6 +4024,8 @@ public fun BooleanArray.take(n: Int): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun CharArray.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3954,6 +4044,8 @@ public fun CharArray.take(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun Array.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3969,6 +4061,8 @@ public fun Array.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ByteArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3984,6 +4078,8 @@ public fun ByteArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun ShortArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -3999,6 +4095,8 @@ public fun ShortArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun IntArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4014,6 +4112,8 @@ public fun IntArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun LongArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4029,6 +4129,8 @@ public fun LongArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun FloatArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4044,6 +4146,8 @@ public fun FloatArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun DoubleArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4059,6 +4163,8 @@ public fun DoubleArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun BooleanArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4074,6 +4180,8 @@ public fun BooleanArray.takeLast(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun CharArray.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -4089,6 +4197,8 @@ public fun CharArray.takeLast(n: Int): List { /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun Array.takeLastWhile(predicate: (T) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4101,6 +4211,8 @@ public inline fun Array.takeLastWhile(predicate: (T) -> Boolean): Lis /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4113,6 +4225,8 @@ public inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -4125,6 +4239,8 @@ public inline fun ShortArray.takeLastWhile(predicate: (Short) -> Boolean): List< /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4137,6 +4253,8 @@ public inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4149,6 +4267,8 @@ public inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List Boolean): List { for (index in lastIndex downTo 0) { @@ -4161,6 +4281,8 @@ public inline fun FloatArray.takeLastWhile(predicate: (Float) -> Boolean): List< /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun DoubleArray.takeLastWhile(predicate: (Double) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4173,6 +4295,8 @@ public inline fun DoubleArray.takeLastWhile(predicate: (Double) -> Boolean): Lis /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun BooleanArray.takeLastWhile(predicate: (Boolean) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4185,6 +4309,8 @@ public inline fun BooleanArray.takeLastWhile(predicate: (Boolean) -> Boolean): L /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List { for (index in lastIndex downTo 0) { @@ -4197,6 +4323,8 @@ public inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List Array.takeWhile(predicate: (T) -> Boolean): List { val list = ArrayList() @@ -4210,6 +4338,8 @@ public inline fun Array.takeWhile(predicate: (T) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List { val list = ArrayList() @@ -4223,6 +4353,8 @@ public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List { val list = ArrayList() @@ -4236,6 +4368,8 @@ public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List Boolean): List { val list = ArrayList() @@ -4249,6 +4383,8 @@ public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List { /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List { val list = ArrayList() @@ -4262,6 +4398,8 @@ public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List { val list = ArrayList() @@ -4275,6 +4413,8 @@ public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List Boolean): List { val list = ArrayList() @@ -4288,6 +4428,8 @@ public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List Boolean): List { val list = ArrayList() @@ -4301,6 +4443,8 @@ public inline fun BooleanArray.takeWhile(predicate: (Boolean) -> Boolean): List< /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun CharArray.takeWhile(predicate: (Char) -> Boolean): List { val list = ArrayList() @@ -13610,7 +13754,7 @@ public fun CharArray.joinTo(buffer: A, separator: CharSequence * * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] * elements will be appended, followed by the [truncated] string (which defaults to "..."). - * + * * @sample samples.collections.Collections.Transformations.joinToString */ public fun Array.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String { @@ -13622,7 +13766,7 @@ public fun Array.joinToString(separator: CharSequence = ", ", prefix: * * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] * elements will be appended, followed by the [truncated] string (which defaults to "..."). - * + * * @sample samples.collections.Collections.Transformations.joinToString */ public fun ByteArray.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((Byte) -> CharSequence)? = null): String { @@ -13646,7 +13790,7 @@ public fun ShortArray.joinToString(separator: CharSequence = ", ", prefix: CharS * * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] * elements will be appended, followed by the [truncated] string (which defaults to "..."). - * + * * @sample samples.collections.Collections.Transformations.joinToString */ public fun IntArray.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((Int) -> CharSequence)? = null): String { diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 68b93471dda..f1b816c9175 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -537,6 +537,8 @@ public inline fun Iterable.singleOrNull(predicate: (T) -> Boolean): T? { /** * Returns a list containing all elements except first [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun Iterable.drop(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -572,6 +574,8 @@ public fun Iterable.drop(n: Int): List { /** * Returns a list containing all elements except last [n] elements. + * + * @sample samples.collections.Collections.Transformations.drop */ public fun List.dropLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -580,6 +584,8 @@ public fun List.dropLast(n: Int): List { /** * Returns a list containing all elements except last elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun List.dropLastWhile(predicate: (T) -> Boolean): List { if (!isEmpty()) { @@ -595,6 +601,8 @@ public inline fun List.dropLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing all elements except first elements that satisfy the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.drop */ public inline fun Iterable.dropWhile(predicate: (T) -> Boolean): List { var yielding = false @@ -729,6 +737,8 @@ public fun List.slice(indices: Iterable): List { /** * Returns a list containing first [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun Iterable.take(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -749,6 +759,8 @@ public fun Iterable.take(n: Int): List { /** * Returns a list containing last [n] elements. + * + * @sample samples.collections.Collections.Transformations.take */ public fun List.takeLast(n: Int): List { require(n >= 0) { "Requested element count $n is less than zero." } @@ -769,6 +781,8 @@ public fun List.takeLast(n: Int): List { /** * Returns a list containing last elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun List.takeLastWhile(predicate: (T) -> Boolean): List { if (isEmpty()) @@ -790,6 +804,8 @@ public inline fun List.takeLastWhile(predicate: (T) -> Boolean): List /** * Returns a list containing first elements satisfying the given [predicate]. + * + * @sample samples.collections.Collections.Transformations.take */ public inline fun Iterable.takeWhile(predicate: (T) -> Boolean): List { val list = ArrayList() @@ -2203,6 +2219,8 @@ public fun Iterable.joinTo(buffer: A, separator: CharSequ * * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit] * elements will be appended, followed by the [truncated] string (which defaults to "..."). + * + * @sample samples.collections.Collections.Transformations.joinToString */ public fun Iterable.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String { return joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString() diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt index 3fcc5f99565..e1df9ded2dc 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt @@ -48,7 +48,13 @@ object Filtering : TemplateGroupBase() { include(CharSequences, Strings) } builder { val n = "\$n" - doc { "Returns a list containing all elements except first [n] elements." } + doc { + """ + Returns a list containing all elements except first [n] elements. + + @sample samples.collections.Collections.Transformations.drop + """ + } returns("List") body { """ @@ -129,7 +135,13 @@ object Filtering : TemplateGroupBase() { include(CharSequences, Strings) } builder { val n = "\$n" - doc { "Returns a list containing first [n] elements." } + doc { + """ + Returns a list containing first [n] elements. + + @sample samples.collections.Collections.Transformations.take + """ + } returns("List") body { """ @@ -204,7 +216,13 @@ object Filtering : TemplateGroupBase() { } builder { val n = "\$n" - doc { "Returns a list containing all elements except last [n] elements." } + doc { + """ + Returns a list containing all elements except last [n] elements. + + @sample samples.collections.Collections.Transformations.drop + """ + } returns("List") body { """ @@ -228,7 +246,14 @@ object Filtering : TemplateGroupBase() { include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings) } builder { val n = "\$n" - doc { "Returns a list containing last [n] elements." } + doc { + """ + Returns a list containing last [n] elements. + + @sample samples.collections.Collections.Transformations.take + """ + } + returns("List") specialFor(Strings, CharSequences) { returns("SELF") @@ -288,7 +313,13 @@ object Filtering : TemplateGroupBase() { } builder { inline() - doc { "Returns a list containing all elements except first elements that satisfy the given [predicate]." } + doc { + """ + Returns a list containing all elements except first elements that satisfy the given [predicate]. + + @sample samples.collections.Collections.Transformations.drop + """ + } returns("List") body { """ @@ -339,7 +370,13 @@ object Filtering : TemplateGroupBase() { } builder { inline() - doc { "Returns a list containing first elements satisfying the given [predicate]." } + doc { + """ + Returns a list containing first elements satisfying the given [predicate]. + + @sample samples.collections.Collections.Transformations.take + """ + } returns("List") body { """ @@ -384,7 +421,13 @@ object Filtering : TemplateGroupBase() { include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings) } builder { inline() - doc { "Returns a list containing all elements except last elements that satisfy the given [predicate]." } + doc { + """ + Returns a list containing all elements except last elements that satisfy the given [predicate]. + + @sample samples.collections.Collections.Transformations.drop + """ + } returns("List") body { @@ -435,7 +478,13 @@ object Filtering : TemplateGroupBase() { include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings) } builder { inline() - doc { "Returns a list containing last elements satisfying the given [predicate]."} + doc { + """ + Returns a list containing last elements satisfying the given [predicate]. + + @sample samples.collections.Collections.Transformations.take + """ + } returns("List") body {