Document exception thrown for negative n in take/takeLast/drop/dropLast

#KT-29151
This commit is contained in:
Ilya Gorbunov
2019-03-12 23:30:07 +03:00
parent 6bc7c06038
commit edc766af56
8 changed files with 147 additions and 2 deletions
@@ -2761,6 +2761,8 @@ public inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): Char? {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Array<out T>.drop(n: Int): List<T> {
@@ -2771,6 +2773,8 @@ public fun <T> Array<out T>.drop(n: Int): List<T> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.drop(n: Int): List<Byte> {
@@ -2781,6 +2785,8 @@ public fun ByteArray.drop(n: Int): List<Byte> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.drop(n: Int): List<Short> {
@@ -2791,6 +2797,8 @@ public fun ShortArray.drop(n: Int): List<Short> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.drop(n: Int): List<Int> {
@@ -2801,6 +2809,8 @@ public fun IntArray.drop(n: Int): List<Int> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.drop(n: Int): List<Long> {
@@ -2811,6 +2821,8 @@ public fun LongArray.drop(n: Int): List<Long> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.drop(n: Int): List<Float> {
@@ -2821,6 +2833,8 @@ public fun FloatArray.drop(n: Int): List<Float> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.drop(n: Int): List<Double> {
@@ -2831,6 +2845,8 @@ public fun DoubleArray.drop(n: Int): List<Double> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.drop(n: Int): List<Boolean> {
@@ -2841,6 +2857,8 @@ public fun BooleanArray.drop(n: Int): List<Boolean> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.drop(n: Int): List<Char> {
@@ -2851,6 +2869,8 @@ public fun CharArray.drop(n: Int): List<Char> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Array<out T>.dropLast(n: Int): List<T> {
@@ -2861,6 +2881,8 @@ public fun <T> Array<out T>.dropLast(n: Int): List<T> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ByteArray.dropLast(n: Int): List<Byte> {
@@ -2871,6 +2893,8 @@ public fun ByteArray.dropLast(n: Int): List<Byte> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun ShortArray.dropLast(n: Int): List<Short> {
@@ -2881,6 +2905,8 @@ public fun ShortArray.dropLast(n: Int): List<Short> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun IntArray.dropLast(n: Int): List<Int> {
@@ -2891,6 +2917,8 @@ public fun IntArray.dropLast(n: Int): List<Int> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun LongArray.dropLast(n: Int): List<Long> {
@@ -2901,6 +2929,8 @@ public fun LongArray.dropLast(n: Int): List<Long> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun FloatArray.dropLast(n: Int): List<Float> {
@@ -2911,6 +2941,8 @@ public fun FloatArray.dropLast(n: Int): List<Float> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun DoubleArray.dropLast(n: Int): List<Double> {
@@ -2921,6 +2953,8 @@ public fun DoubleArray.dropLast(n: Int): List<Double> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun BooleanArray.dropLast(n: Int): List<Boolean> {
@@ -2931,6 +2965,8 @@ public fun BooleanArray.dropLast(n: Int): List<Boolean> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun CharArray.dropLast(n: Int): List<Char> {
@@ -4087,6 +4123,8 @@ public fun CharArray.sliceArray(indices: IntRange): CharArray {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Array<out T>.take(n: Int): List<T> {
@@ -4107,6 +4145,8 @@ public fun <T> Array<out T>.take(n: Int): List<T> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ByteArray.take(n: Int): List<Byte> {
@@ -4127,6 +4167,8 @@ public fun ByteArray.take(n: Int): List<Byte> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ShortArray.take(n: Int): List<Short> {
@@ -4147,6 +4189,8 @@ public fun ShortArray.take(n: Int): List<Short> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun IntArray.take(n: Int): List<Int> {
@@ -4167,6 +4211,8 @@ public fun IntArray.take(n: Int): List<Int> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun LongArray.take(n: Int): List<Long> {
@@ -4187,6 +4233,8 @@ public fun LongArray.take(n: Int): List<Long> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun FloatArray.take(n: Int): List<Float> {
@@ -4207,6 +4255,8 @@ public fun FloatArray.take(n: Int): List<Float> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun DoubleArray.take(n: Int): List<Double> {
@@ -4227,6 +4277,8 @@ public fun DoubleArray.take(n: Int): List<Double> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun BooleanArray.take(n: Int): List<Boolean> {
@@ -4247,6 +4299,8 @@ public fun BooleanArray.take(n: Int): List<Boolean> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun CharArray.take(n: Int): List<Char> {
@@ -4267,6 +4321,8 @@ public fun CharArray.take(n: Int): List<Char> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Array<out T>.takeLast(n: Int): List<T> {
@@ -4284,6 +4340,8 @@ public fun <T> Array<out T>.takeLast(n: Int): List<T> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ByteArray.takeLast(n: Int): List<Byte> {
@@ -4301,6 +4359,8 @@ public fun ByteArray.takeLast(n: Int): List<Byte> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun ShortArray.takeLast(n: Int): List<Short> {
@@ -4318,6 +4378,8 @@ public fun ShortArray.takeLast(n: Int): List<Short> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun IntArray.takeLast(n: Int): List<Int> {
@@ -4335,6 +4397,8 @@ public fun IntArray.takeLast(n: Int): List<Int> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun LongArray.takeLast(n: Int): List<Long> {
@@ -4352,6 +4416,8 @@ public fun LongArray.takeLast(n: Int): List<Long> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun FloatArray.takeLast(n: Int): List<Float> {
@@ -4369,6 +4435,8 @@ public fun FloatArray.takeLast(n: Int): List<Float> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun DoubleArray.takeLast(n: Int): List<Double> {
@@ -4386,6 +4454,8 @@ public fun DoubleArray.takeLast(n: Int): List<Double> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun BooleanArray.takeLast(n: Int): List<Boolean> {
@@ -4403,6 +4473,8 @@ public fun BooleanArray.takeLast(n: Int): List<Boolean> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun CharArray.takeLast(n: Int): List<Char> {
@@ -581,6 +581,8 @@ public inline fun <T> Iterable<T>.singleOrNull(predicate: (T) -> Boolean): T? {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Iterable<T>.drop(n: Int): List<T> {
@@ -618,6 +620,8 @@ public fun <T> Iterable<T>.drop(n: Int): List<T> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> List<T>.dropLast(n: Int): List<T> {
@@ -765,6 +769,8 @@ public fun <T> List<T>.slice(indices: Iterable<Int>): List<T> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Iterable<T>.take(n: Int): List<T> {
@@ -787,6 +793,8 @@ public fun <T> Iterable<T>.take(n: Int): List<T> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> List<T>.takeLast(n: Int): List<T> {
@@ -347,6 +347,8 @@ public inline fun <T> Sequence<T>.singleOrNull(predicate: (T) -> Boolean): T? {
*
* The operation is _intermediate_ and _stateless_.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
public fun <T> Sequence<T>.drop(n: Int): Sequence<T> {
@@ -478,6 +480,8 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destinat
*
* The operation is _intermediate_ and _stateless_.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
public fun <T> Sequence<T>.take(n: Int): Sequence<T> {
@@ -250,6 +250,8 @@ public inline fun CharSequence.singleOrNull(predicate: (Char) -> Boolean): Char?
/**
* Returns a subsequence of this char sequence with the first [n] characters removed.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.drop
*/
public fun CharSequence.drop(n: Int): CharSequence {
@@ -260,6 +262,8 @@ public fun CharSequence.drop(n: Int): CharSequence {
/**
* Returns a string with the first [n] characters removed.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.drop
*/
public fun String.drop(n: Int): String {
@@ -270,6 +274,8 @@ public fun String.drop(n: Int): String {
/**
* Returns a subsequence of this char sequence with the last [n] characters removed.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.drop
*/
public fun CharSequence.dropLast(n: Int): CharSequence {
@@ -280,6 +286,8 @@ public fun CharSequence.dropLast(n: Int): CharSequence {
/**
* Returns a string with the last [n] characters removed.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.drop
*/
public fun String.dropLast(n: Int): String {
@@ -452,6 +460,8 @@ public inline fun String.slice(indices: Iterable<Int>): String {
/**
* Returns a subsequence of this char sequence containing the first [n] characters from this char sequence, or the entire char sequence if this char sequence is shorter.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.take
*/
public fun CharSequence.take(n: Int): CharSequence {
@@ -462,6 +472,8 @@ public fun CharSequence.take(n: Int): CharSequence {
/**
* Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.take
*/
public fun String.take(n: Int): String {
@@ -472,6 +484,8 @@ public fun String.take(n: Int): String {
/**
* Returns a subsequence of this char sequence containing the last [n] characters from this char sequence, or the entire char sequence if this char sequence is shorter.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.take
*/
public fun CharSequence.takeLast(n: Int): CharSequence {
@@ -483,6 +497,8 @@ public fun CharSequence.takeLast(n: Int): CharSequence {
/**
* Returns a string containing the last [n] characters from this string, or the entire string if this string is shorter.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.text.Strings.take
*/
public fun String.takeLast(n: Int): String {
@@ -1375,6 +1375,8 @@ public inline fun UShortArray.singleOrNull(predicate: (UShort) -> Boolean): USho
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1387,6 +1389,8 @@ public fun UIntArray.drop(n: Int): List<UInt> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1399,6 +1403,8 @@ public fun ULongArray.drop(n: Int): List<ULong> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1411,6 +1417,8 @@ public fun UByteArray.drop(n: Int): List<UByte> {
/**
* Returns a list containing all elements except first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1423,6 +1431,8 @@ public fun UShortArray.drop(n: Int): List<UShort> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1435,6 +1445,8 @@ public fun UIntArray.dropLast(n: Int): List<UInt> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1447,6 +1459,8 @@ public fun ULongArray.dropLast(n: Int): List<ULong> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -1459,6 +1473,8 @@ public fun UByteArray.dropLast(n: Int): List<UByte> {
/**
* Returns a list containing all elements except last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.drop
*/
@SinceKotlin("1.3")
@@ -2071,6 +2087,8 @@ public fun UShortArray.sliceArray(indices: IntRange): UShortArray {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2093,6 +2111,8 @@ public fun UIntArray.take(n: Int): List<UInt> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2115,6 +2135,8 @@ public fun ULongArray.take(n: Int): List<ULong> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2137,6 +2159,8 @@ public fun UByteArray.take(n: Int): List<UByte> {
/**
* Returns a list containing first [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2159,6 +2183,8 @@ public fun UShortArray.take(n: Int): List<UShort> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2178,6 +2204,8 @@ public fun UIntArray.takeLast(n: Int): List<UInt> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2197,6 +2225,8 @@ public fun ULongArray.takeLast(n: Int): List<ULong> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")
@@ -2216,6 +2246,8 @@ public fun UByteArray.takeLast(n: Int): List<UByte> {
/**
* Returns a list containing last [n] elements.
*
* @throws IllegalArgumentException if [n] is negative.
*
* @sample samples.collections.Collections.Transformations.take
*/
@SinceKotlin("1.3")