Add samples for take* and drop* extensions (KT-20357)

- Add samples for take, takeLast, takeWhile, takeLastWhile
- Add samples for drop, dropLast, dropWhile, dropLastWhile
This commit is contained in:
gzoritchak
2018-02-20 00:45:48 +01:00
committed by Ilya Gorbunov
parent fda40723dc
commit 1c1fe10e12
8 changed files with 562 additions and 14 deletions
@@ -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 <T> Array<out T>.drop(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2532,6 +2534,8 @@ public fun <T> Array<out T>.drop(n: Int): List<T> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.drop(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2540,6 +2544,8 @@ public fun ByteArray.drop(n: Int): List<Byte> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.drop(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2548,6 +2554,8 @@ public fun ShortArray.drop(n: Int): List<Short> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.drop(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2556,6 +2564,8 @@ public fun IntArray.drop(n: Int): List<Int> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.drop(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2564,6 +2574,8 @@ public fun LongArray.drop(n: Int): List<Long> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.drop(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2572,6 +2584,8 @@ public fun FloatArray.drop(n: Int): List<Float> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.drop(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2580,6 +2594,8 @@ public fun DoubleArray.drop(n: Int): List<Double> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.drop(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2588,6 +2604,8 @@ public fun BooleanArray.drop(n: Int): List<Boolean> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.drop(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2596,6 +2614,8 @@ public fun CharArray.drop(n: Int): List<Char> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Array<out T>.dropLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2604,6 +2624,8 @@ public fun <T> Array<out T>.dropLast(n: Int): List<T> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.dropLast(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2612,6 +2634,8 @@ public fun ByteArray.dropLast(n: Int): List<Byte> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.dropLast(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2620,6 +2644,8 @@ public fun ShortArray.dropLast(n: Int): List<Short> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.dropLast(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2628,6 +2654,8 @@ public fun IntArray.dropLast(n: Int): List<Int> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.dropLast(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2636,6 +2664,8 @@ public fun LongArray.dropLast(n: Int): List<Long> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.dropLast(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2644,6 +2674,8 @@ public fun FloatArray.dropLast(n: Int): List<Float> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.dropLast(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2652,6 +2684,8 @@ public fun DoubleArray.dropLast(n: Int): List<Double> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.dropLast(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2660,6 +2694,8 @@ public fun BooleanArray.dropLast(n: Int): List<Boolean> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.dropLast(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2668,6 +2704,8 @@ public fun CharArray.dropLast(n: Int): List<Char> {
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> Array<out T>.dropLastWhile(predicate: (T) -> Boolean): List<T> {
for (index in lastIndex downTo 0) {
@@ -2680,6 +2718,8 @@ public inline fun <T> Array<out T>.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<Byte> {
for (index in lastIndex downTo 0) {
@@ -2692,6 +2732,8 @@ public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List<By
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun ShortArray.dropLastWhile(predicate: (Short) -> Boolean): List<Short> {
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<Int> {
for (index in lastIndex downTo 0) {
@@ -2716,6 +2760,8 @@ public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List<Int>
/**
* 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<Long> {
for (index in lastIndex downTo 0) {
@@ -2728,6 +2774,8 @@ public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List<Lo
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun FloatArray.dropLastWhile(predicate: (Float) -> Boolean): List<Float> {
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<Double> {
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<Boolean> {
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<Char> {
for (index in lastIndex downTo 0) {
@@ -2776,6 +2830,8 @@ public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List<Ch
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> Array<out T>.dropWhile(predicate: (T) -> Boolean): List<T> {
var yielding = false
@@ -2792,6 +2848,8 @@ public inline fun <T> Array<out T>.dropWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte> {
var yielding = false
@@ -2808,6 +2866,8 @@ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List<Byte>
/**
* 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<Short> {
var yielding = false
@@ -2824,6 +2884,8 @@ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List<Shor
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List<Int> {
var yielding = false
@@ -2840,6 +2902,8 @@ public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List<Int> {
/**
* 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<Long> {
var yielding = false
@@ -2856,6 +2920,8 @@ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List<Long>
/**
* 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<Float> {
var yielding = false
@@ -2872,6 +2938,8 @@ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List<Floa
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List<Double> {
var yielding = false
@@ -2888,6 +2956,8 @@ public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List<Do
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List<Boolean> {
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<Char> {
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 <T> Array<out T>.take(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3796,6 +3870,8 @@ public fun <T> Array<out T>.take(n: Int): List<T> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ByteArray.take(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3814,6 +3890,8 @@ public fun ByteArray.take(n: Int): List<Byte> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ShortArray.take(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3832,6 +3910,8 @@ public fun ShortArray.take(n: Int): List<Short> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun IntArray.take(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3850,6 +3930,8 @@ public fun IntArray.take(n: Int): List<Int> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun LongArray.take(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3868,6 +3950,8 @@ public fun LongArray.take(n: Int): List<Long> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun FloatArray.take(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3886,6 +3970,8 @@ public fun FloatArray.take(n: Int): List<Float> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun DoubleArray.take(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3904,6 +3990,8 @@ public fun DoubleArray.take(n: Int): List<Double> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun BooleanArray.take(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3922,6 +4010,8 @@ public fun BooleanArray.take(n: Int): List<Boolean> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun CharArray.take(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3940,6 +4030,8 @@ public fun CharArray.take(n: Int): List<Char> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Array<out T>.takeLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3955,6 +4047,8 @@ public fun <T> Array<out T>.takeLast(n: Int): List<T> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ByteArray.takeLast(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3970,6 +4064,8 @@ public fun ByteArray.takeLast(n: Int): List<Byte> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ShortArray.takeLast(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3985,6 +4081,8 @@ public fun ShortArray.takeLast(n: Int): List<Short> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun IntArray.takeLast(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4000,6 +4098,8 @@ public fun IntArray.takeLast(n: Int): List<Int> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun LongArray.takeLast(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4015,6 +4115,8 @@ public fun LongArray.takeLast(n: Int): List<Long> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun FloatArray.takeLast(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4030,6 +4132,8 @@ public fun FloatArray.takeLast(n: Int): List<Float> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun DoubleArray.takeLast(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4045,6 +4149,8 @@ public fun DoubleArray.takeLast(n: Int): List<Double> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun BooleanArray.takeLast(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4060,6 +4166,8 @@ public fun BooleanArray.takeLast(n: Int): List<Boolean> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun CharArray.takeLast(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4075,6 +4183,8 @@ public fun CharArray.takeLast(n: Int): List<Char> {
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> Array<out T>.takeLastWhile(predicate: (T) -> Boolean): List<T> {
for (index in lastIndex downTo 0) {
@@ -4087,6 +4197,8 @@ public inline fun <T> Array<out T>.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<Byte> {
for (index in lastIndex downTo 0) {
@@ -4099,6 +4211,8 @@ public inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List<By
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun ShortArray.takeLastWhile(predicate: (Short) -> Boolean): List<Short> {
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<Int> {
for (index in lastIndex downTo 0) {
@@ -4123,6 +4239,8 @@ public inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List<Int>
/**
* 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<Long> {
for (index in lastIndex downTo 0) {
@@ -4135,6 +4253,8 @@ public inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List<Lo
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun FloatArray.takeLastWhile(predicate: (Float) -> Boolean): List<Float> {
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<Double> {
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<Boolean> {
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<Char> {
for (index in lastIndex downTo 0) {
@@ -4183,6 +4309,8 @@ public inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List<Ch
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> Array<out T>.takeWhile(predicate: (T) -> Boolean): List<T> {
val list = ArrayList<T>()
@@ -4196,6 +4324,8 @@ public inline fun <T> Array<out T>.takeWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte> {
val list = ArrayList<Byte>()
@@ -4209,6 +4339,8 @@ public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List<Byte>
/**
* 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<Short> {
val list = ArrayList<Short>()
@@ -4222,6 +4354,8 @@ public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List<Shor
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List<Int> {
val list = ArrayList<Int>()
@@ -4235,6 +4369,8 @@ public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List<Int> {
/**
* 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<Long> {
val list = ArrayList<Long>()
@@ -4248,6 +4384,8 @@ public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List<Long>
/**
* 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<Float> {
val list = ArrayList<Float>()
@@ -4261,6 +4399,8 @@ public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List<Floa
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List<Double> {
val list = ArrayList<Double>()
@@ -4274,6 +4414,8 @@ public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List<Do
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun BooleanArray.takeWhile(predicate: (Boolean) -> Boolean): List<Boolean> {
val list = ArrayList<Boolean>()
@@ -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<Char> {
val list = ArrayList<Char>()
@@ -537,6 +537,8 @@ public inline fun <T> Iterable<T>.singleOrNull(predicate: (T) -> Boolean): T? {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Iterable<T>.drop(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -572,6 +574,8 @@ public fun <T> Iterable<T>.drop(n: Int): List<T> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> List<T>.dropLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -580,6 +584,8 @@ public fun <T> List<T>.dropLast(n: Int): List<T> {
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> List<T>.dropLastWhile(predicate: (T) -> Boolean): List<T> {
if (!isEmpty()) {
@@ -595,6 +601,8 @@ public inline fun <T> List<T>.dropLastWhile(predicate: (T) -> Boolean): List<T>
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean): List<T> {
var yielding = false
@@ -713,6 +721,8 @@ public fun <T> List<T>.slice(indices: Iterable<Int>): List<T> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Iterable<T>.take(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -733,6 +743,8 @@ public fun <T> Iterable<T>.take(n: Int): List<T> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> List<T>.takeLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -753,6 +765,8 @@ public fun <T> List<T>.takeLast(n: Int): List<T> {
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> List<T>.takeLastWhile(predicate: (T) -> Boolean): List<T> {
if (isEmpty())
@@ -774,6 +788,8 @@ public inline fun <T> List<T>.takeLastWhile(predicate: (T) -> Boolean): List<T>
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> {
val list = ArrayList<T>()
@@ -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 <T> Array<out T>.drop(n: Int): List<T>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun ByteArray.drop(n: Int): List<Byte>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun ShortArray.drop(n: Int): List<Short>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun IntArray.drop(n: Int): List<Int>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun LongArray.drop(n: Int): List<Long>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun FloatArray.drop(n: Int): List<Float>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun DoubleArray.drop(n: Int): List<Double>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun BooleanArray.drop(n: Int): List<Boolean>
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun CharArray.drop(n: Int): List<Char>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun <T> Array<out T>.dropLast(n: Int): List<T>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun ByteArray.dropLast(n: Int): List<Byte>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun ShortArray.dropLast(n: Int): List<Short>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun IntArray.dropLast(n: Int): List<Int>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun LongArray.dropLast(n: Int): List<Long>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun FloatArray.dropLast(n: Int): List<Float>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun DoubleArray.dropLast(n: Int): List<Double>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun BooleanArray.dropLast(n: Int): List<Boolean>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun CharArray.dropLast(n: Int): List<Char>
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect inline fun <T> Array<out T>.dropLastWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte>
/**
* 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<Short>
/**
* 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<Int>
/**
* 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<Long>
/**
* 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<Float>
/**
* 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<Double>
/**
* 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<Boolean>
/**
* 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<Char>
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect inline fun <T> Array<out T>.dropWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte>
/**
* 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<Short>
/**
* 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<Int>
/**
* 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<Long>
/**
* 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<Float>
/**
* 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<Double>
/**
* 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<Boolean>
/**
* 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<Char>
@@ -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 <T> Array<out T>.take(n: Int): List<T>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun ByteArray.take(n: Int): List<Byte>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun ShortArray.take(n: Int): List<Short>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun IntArray.take(n: Int): List<Int>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun LongArray.take(n: Int): List<Long>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun FloatArray.take(n: Int): List<Float>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun DoubleArray.take(n: Int): List<Double>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun BooleanArray.take(n: Int): List<Boolean>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun CharArray.take(n: Int): List<Char>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun <T> Array<out T>.takeLast(n: Int): List<T>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun ByteArray.takeLast(n: Int): List<Byte>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun ShortArray.takeLast(n: Int): List<Short>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun IntArray.takeLast(n: Int): List<Int>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun LongArray.takeLast(n: Int): List<Long>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun FloatArray.takeLast(n: Int): List<Float>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun DoubleArray.takeLast(n: Int): List<Double>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun BooleanArray.takeLast(n: Int): List<Boolean>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun CharArray.takeLast(n: Int): List<Char>
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect inline fun <T> Array<out T>.takeLastWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte>
/**
* 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<Short>
/**
* 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<Int>
/**
* 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<Long>
/**
* 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<Float>
/**
* 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<Double>
/**
* 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<Boolean>
/**
* 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<Char>
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect inline fun <T> Array<out T>.takeWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte>
/**
* 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<Short>
/**
* 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<Int>
/**
* 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<Long>
/**
* 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<Float>
/**
* 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<Double>
/**
* 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<Boolean>
/**
* 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<Char>
@@ -258,21 +258,29 @@ public expect inline fun <T> Iterable<T>.singleOrNull(predicate: (T) -> Boolean)
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun <T> Iterable<T>.drop(n: Int): List<T>
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect fun <T> List<T>.dropLast(n: Int): List<T>
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect inline fun <T> List<T>.dropLastWhile(predicate: (T) -> Boolean): List<T>
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public expect inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean): List<T>
@@ -342,21 +350,29 @@ public expect fun <T> List<T>.slice(indices: Iterable<Int>): List<T>
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun <T> Iterable<T>.take(n: Int): List<T>
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect fun <T> List<T>.takeLast(n: Int): List<T>
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect inline fun <T> List<T>.takeLastWhile(predicate: (T) -> Boolean): List<T>
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public expect inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T>
@@ -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<Int> = 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()
+147 -3
View File
@@ -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 <T> Array<out T>.drop(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2530,6 +2532,8 @@ public fun <T> Array<out T>.drop(n: Int): List<T> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.drop(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2538,6 +2542,8 @@ public fun ByteArray.drop(n: Int): List<Byte> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.drop(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2546,6 +2552,8 @@ public fun ShortArray.drop(n: Int): List<Short> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.drop(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2554,6 +2562,8 @@ public fun IntArray.drop(n: Int): List<Int> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.drop(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2562,6 +2572,8 @@ public fun LongArray.drop(n: Int): List<Long> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.drop(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2570,6 +2582,8 @@ public fun FloatArray.drop(n: Int): List<Float> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.drop(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2578,6 +2592,8 @@ public fun DoubleArray.drop(n: Int): List<Double> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.drop(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2586,6 +2602,8 @@ public fun BooleanArray.drop(n: Int): List<Boolean> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.drop(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2594,6 +2612,8 @@ public fun CharArray.drop(n: Int): List<Char> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Array<out T>.dropLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2602,6 +2622,8 @@ public fun <T> Array<out T>.dropLast(n: Int): List<T> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.dropLast(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2610,6 +2632,8 @@ public fun ByteArray.dropLast(n: Int): List<Byte> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.dropLast(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2618,6 +2642,8 @@ public fun ShortArray.dropLast(n: Int): List<Short> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.dropLast(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2626,6 +2652,8 @@ public fun IntArray.dropLast(n: Int): List<Int> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.dropLast(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2634,6 +2662,8 @@ public fun LongArray.dropLast(n: Int): List<Long> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.dropLast(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2642,6 +2672,8 @@ public fun FloatArray.dropLast(n: Int): List<Float> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.dropLast(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2650,6 +2682,8 @@ public fun DoubleArray.dropLast(n: Int): List<Double> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.dropLast(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2658,6 +2692,8 @@ public fun BooleanArray.dropLast(n: Int): List<Boolean> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.dropLast(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -2666,6 +2702,8 @@ public fun CharArray.dropLast(n: Int): List<Char> {
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> Array<out T>.dropLastWhile(predicate: (T) -> Boolean): List<T> {
for (index in lastIndex downTo 0) {
@@ -2678,6 +2716,8 @@ public inline fun <T> Array<out T>.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<Byte> {
for (index in lastIndex downTo 0) {
@@ -2690,6 +2730,8 @@ public inline fun ByteArray.dropLastWhile(predicate: (Byte) -> Boolean): List<By
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun ShortArray.dropLastWhile(predicate: (Short) -> Boolean): List<Short> {
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<Int> {
for (index in lastIndex downTo 0) {
@@ -2714,6 +2758,8 @@ public inline fun IntArray.dropLastWhile(predicate: (Int) -> Boolean): List<Int>
/**
* 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<Long> {
for (index in lastIndex downTo 0) {
@@ -2726,6 +2772,8 @@ public inline fun LongArray.dropLastWhile(predicate: (Long) -> Boolean): List<Lo
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun FloatArray.dropLastWhile(predicate: (Float) -> Boolean): List<Float> {
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<Double> {
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<Boolean> {
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<Char> {
for (index in lastIndex downTo 0) {
@@ -2774,6 +2828,8 @@ public inline fun CharArray.dropLastWhile(predicate: (Char) -> Boolean): List<Ch
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> Array<out T>.dropWhile(predicate: (T) -> Boolean): List<T> {
var yielding = false
@@ -2790,6 +2846,8 @@ public inline fun <T> Array<out T>.dropWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte> {
var yielding = false
@@ -2806,6 +2864,8 @@ public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List<Byte>
/**
* 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<Short> {
var yielding = false
@@ -2822,6 +2882,8 @@ public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List<Shor
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List<Int> {
var yielding = false
@@ -2838,6 +2900,8 @@ public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List<Int> {
/**
* 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<Long> {
var yielding = false
@@ -2854,6 +2918,8 @@ public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List<Long>
/**
* 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<Float> {
var yielding = false
@@ -2870,6 +2936,8 @@ public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List<Floa
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List<Double> {
var yielding = false
@@ -2886,6 +2954,8 @@ public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List<Do
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List<Boolean> {
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<Char> {
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 <T> Array<out T>.take(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3810,6 +3884,8 @@ public fun <T> Array<out T>.take(n: Int): List<T> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ByteArray.take(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3828,6 +3904,8 @@ public fun ByteArray.take(n: Int): List<Byte> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ShortArray.take(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3846,6 +3924,8 @@ public fun ShortArray.take(n: Int): List<Short> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun IntArray.take(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3864,6 +3944,8 @@ public fun IntArray.take(n: Int): List<Int> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun LongArray.take(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3882,6 +3964,8 @@ public fun LongArray.take(n: Int): List<Long> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun FloatArray.take(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3900,6 +3984,8 @@ public fun FloatArray.take(n: Int): List<Float> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun DoubleArray.take(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3918,6 +4004,8 @@ public fun DoubleArray.take(n: Int): List<Double> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun BooleanArray.take(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3936,6 +4024,8 @@ public fun BooleanArray.take(n: Int): List<Boolean> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun CharArray.take(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3954,6 +4044,8 @@ public fun CharArray.take(n: Int): List<Char> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Array<out T>.takeLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3969,6 +4061,8 @@ public fun <T> Array<out T>.takeLast(n: Int): List<T> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ByteArray.takeLast(n: Int): List<Byte> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3984,6 +4078,8 @@ public fun ByteArray.takeLast(n: Int): List<Byte> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ShortArray.takeLast(n: Int): List<Short> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -3999,6 +4095,8 @@ public fun ShortArray.takeLast(n: Int): List<Short> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun IntArray.takeLast(n: Int): List<Int> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4014,6 +4112,8 @@ public fun IntArray.takeLast(n: Int): List<Int> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun LongArray.takeLast(n: Int): List<Long> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4029,6 +4129,8 @@ public fun LongArray.takeLast(n: Int): List<Long> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun FloatArray.takeLast(n: Int): List<Float> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4044,6 +4146,8 @@ public fun FloatArray.takeLast(n: Int): List<Float> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun DoubleArray.takeLast(n: Int): List<Double> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4059,6 +4163,8 @@ public fun DoubleArray.takeLast(n: Int): List<Double> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun BooleanArray.takeLast(n: Int): List<Boolean> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4074,6 +4180,8 @@ public fun BooleanArray.takeLast(n: Int): List<Boolean> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun CharArray.takeLast(n: Int): List<Char> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -4089,6 +4197,8 @@ public fun CharArray.takeLast(n: Int): List<Char> {
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> Array<out T>.takeLastWhile(predicate: (T) -> Boolean): List<T> {
for (index in lastIndex downTo 0) {
@@ -4101,6 +4211,8 @@ public inline fun <T> Array<out T>.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<Byte> {
for (index in lastIndex downTo 0) {
@@ -4113,6 +4225,8 @@ public inline fun ByteArray.takeLastWhile(predicate: (Byte) -> Boolean): List<By
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun ShortArray.takeLastWhile(predicate: (Short) -> Boolean): List<Short> {
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<Int> {
for (index in lastIndex downTo 0) {
@@ -4137,6 +4253,8 @@ public inline fun IntArray.takeLastWhile(predicate: (Int) -> Boolean): List<Int>
/**
* 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<Long> {
for (index in lastIndex downTo 0) {
@@ -4149,6 +4267,8 @@ public inline fun LongArray.takeLastWhile(predicate: (Long) -> Boolean): List<Lo
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun FloatArray.takeLastWhile(predicate: (Float) -> Boolean): List<Float> {
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<Double> {
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<Boolean> {
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<Char> {
for (index in lastIndex downTo 0) {
@@ -4197,6 +4323,8 @@ public inline fun CharArray.takeLastWhile(predicate: (Char) -> Boolean): List<Ch
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> Array<out T>.takeWhile(predicate: (T) -> Boolean): List<T> {
val list = ArrayList<T>()
@@ -4210,6 +4338,8 @@ public inline fun <T> Array<out T>.takeWhile(predicate: (T) -> Boolean): List<T>
/**
* 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<Byte> {
val list = ArrayList<Byte>()
@@ -4223,6 +4353,8 @@ public inline fun ByteArray.takeWhile(predicate: (Byte) -> Boolean): List<Byte>
/**
* 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<Short> {
val list = ArrayList<Short>()
@@ -4236,6 +4368,8 @@ public inline fun ShortArray.takeWhile(predicate: (Short) -> Boolean): List<Shor
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List<Int> {
val list = ArrayList<Int>()
@@ -4249,6 +4383,8 @@ public inline fun IntArray.takeWhile(predicate: (Int) -> Boolean): List<Int> {
/**
* 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<Long> {
val list = ArrayList<Long>()
@@ -4262,6 +4398,8 @@ public inline fun LongArray.takeWhile(predicate: (Long) -> Boolean): List<Long>
/**
* 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<Float> {
val list = ArrayList<Float>()
@@ -4275,6 +4413,8 @@ public inline fun FloatArray.takeWhile(predicate: (Float) -> Boolean): List<Floa
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List<Double> {
val list = ArrayList<Double>()
@@ -4288,6 +4428,8 @@ public inline fun DoubleArray.takeWhile(predicate: (Double) -> Boolean): List<Do
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun BooleanArray.takeWhile(predicate: (Boolean) -> Boolean): List<Boolean> {
val list = ArrayList<Boolean>()
@@ -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<Char> {
val list = ArrayList<Char>()
@@ -13610,7 +13754,7 @@ public fun <A : Appendable> 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 <T> Array<out T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
@@ -13622,7 +13766,7 @@ public fun <T> Array<out T>.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 {
@@ -537,6 +537,8 @@ public inline fun <T> Iterable<T>.singleOrNull(predicate: (T) -> Boolean): T? {
/**
* Returns a list containing all elements except first [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Iterable<T>.drop(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -572,6 +574,8 @@ public fun <T> Iterable<T>.drop(n: Int): List<T> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> List<T>.dropLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -580,6 +584,8 @@ public fun <T> List<T>.dropLast(n: Int): List<T> {
/**
* Returns a list containing all elements except last elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> List<T>.dropLastWhile(predicate: (T) -> Boolean): List<T> {
if (!isEmpty()) {
@@ -595,6 +601,8 @@ public inline fun <T> List<T>.dropLastWhile(predicate: (T) -> Boolean): List<T>
/**
* Returns a list containing all elements except first elements that satisfy the given [predicate].
*
* @sample samples.collections.Collections.Transformations.drop
*/
public inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean): List<T> {
var yielding = false
@@ -729,6 +737,8 @@ public fun <T> List<T>.slice(indices: Iterable<Int>): List<T> {
/**
* Returns a list containing first [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Iterable<T>.take(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -749,6 +759,8 @@ public fun <T> Iterable<T>.take(n: Int): List<T> {
/**
* Returns a list containing last [n] elements.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> List<T>.takeLast(n: Int): List<T> {
require(n >= 0) { "Requested element count $n is less than zero." }
@@ -769,6 +781,8 @@ public fun <T> List<T>.takeLast(n: Int): List<T> {
/**
* Returns a list containing last elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> List<T>.takeLastWhile(predicate: (T) -> Boolean): List<T> {
if (isEmpty())
@@ -790,6 +804,8 @@ public inline fun <T> List<T>.takeLastWhile(predicate: (T) -> Boolean): List<T>
/**
* Returns a list containing first elements satisfying the given [predicate].
*
* @sample samples.collections.Collections.Transformations.take
*/
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> {
val list = ArrayList<T>()
@@ -2203,6 +2219,8 @@ public fun <T, A : Appendable> Iterable<T>.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 <T> Iterable<T>.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()
@@ -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<T>")
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<T>")
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<T>")
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<T>")
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<T>")
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<T>")
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<T>")
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<T>")
body {