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:
committed by
Ilya Gorbunov
parent
fda40723dc
commit
1c1fe10e12
@@ -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>()
|
||||
|
||||
Reference in New Issue
Block a user