#KT-2067 Fixed
This commit is contained in:
@@ -175,6 +175,20 @@ public inline fun <T> Array<T>.makeString(separator: String = ", ", prefix: Stri
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <T, L: List<in T>> Array<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <T, L: List<in T>> Array<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun <in T> Array<T?>?.requireNoNulls() : List<T> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun <T> Array<T>.drop(n: Int): List<T> {
|
||||
fun countTo(n: Int): (T) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun <T> Array<T>.dropWhile(predicate: (T) -> Boolean): List<T> = dropWhileTo(ArrayList<T>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun BooleanArray.makeString(separator: String = ", ", prefix: Stri
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Boolean>> BooleanArray.dropWhileTo(result: L, predicate: (Boolean) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Boolean>> BooleanArray.takeWhileTo(result: L, predicate: (Boolean) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun BooleanArray?.requireNoNulls() : List<Boolean> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun BooleanArray.drop(n: Int): List<Boolean> {
|
||||
fun countTo(n: Int): (Boolean) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun BooleanArray.dropWhile(predicate: (Boolean) -> Boolean): List<Boolean> = dropWhileTo(ArrayList<Boolean>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun ByteArray.makeString(separator: String = ", ", prefix: String
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Byte>> ByteArray.dropWhileTo(result: L, predicate: (Byte) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Byte>> ByteArray.takeWhileTo(result: L, predicate: (Byte) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun ByteArray?.requireNoNulls() : List<Byte> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun ByteArray.drop(n: Int): List<Byte> {
|
||||
fun countTo(n: Int): (Byte) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun ByteArray.dropWhile(predicate: (Byte) -> Boolean): List<Byte> = dropWhileTo(ArrayList<Byte>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun CharArray.makeString(separator: String = ", ", prefix: String
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Char>> CharArray.dropWhileTo(result: L, predicate: (Char) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Char>> CharArray.takeWhileTo(result: L, predicate: (Char) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun CharArray?.requireNoNulls() : List<Char> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun CharArray.drop(n: Int): List<Char> {
|
||||
fun countTo(n: Int): (Char) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun CharArray.dropWhile(predicate: (Char) -> Boolean): List<Char> = dropWhileTo(ArrayList<Char>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun DoubleArray.makeString(separator: String = ", ", prefix: Strin
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Double>> DoubleArray.dropWhileTo(result: L, predicate: (Double) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Double>> DoubleArray.takeWhileTo(result: L, predicate: (Double) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun DoubleArray?.requireNoNulls() : List<Double> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun DoubleArray.drop(n: Int): List<Double> {
|
||||
fun countTo(n: Int): (Double) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun DoubleArray.dropWhile(predicate: (Double) -> Boolean): List<Double> = dropWhileTo(ArrayList<Double>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun FloatArray.makeString(separator: String = ", ", prefix: String
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Float>> FloatArray.dropWhileTo(result: L, predicate: (Float) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Float>> FloatArray.takeWhileTo(result: L, predicate: (Float) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun FloatArray?.requireNoNulls() : List<Float> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun FloatArray.drop(n: Int): List<Float> {
|
||||
fun countTo(n: Int): (Float) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun FloatArray.dropWhile(predicate: (Float) -> Boolean): List<Float> = dropWhileTo(ArrayList<Float>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun IntArray.makeString(separator: String = ", ", prefix: String =
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Int>> IntArray.dropWhileTo(result: L, predicate: (Int) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Int>> IntArray.takeWhileTo(result: L, predicate: (Int) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun IntArray?.requireNoNulls() : List<Int> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun IntArray.drop(n: Int): List<Int> {
|
||||
fun countTo(n: Int): (Int) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun IntArray.dropWhile(predicate: (Int) -> Boolean): List<Int> = dropWhileTo(ArrayList<Int>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -173,6 +173,20 @@ public inline fun <T> java.util.Iterator<T>.makeString(separator: String = ", ",
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <T, L: List<in T>> java.util.Iterator<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <T, L: List<in T>> java.util.Iterator<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun LongArray.makeString(separator: String = ", ", prefix: String
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Long>> LongArray.dropWhileTo(result: L, predicate: (Long) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Long>> LongArray.takeWhileTo(result: L, predicate: (Long) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun LongArray?.requireNoNulls() : List<Long> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun LongArray.drop(n: Int): List<Long> {
|
||||
fun countTo(n: Int): (Long) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun LongArray.dropWhile(predicate: (Long) -> Boolean): List<Long> = dropWhileTo(ArrayList<Long>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun ShortArray.makeString(separator: String = ", ", prefix: String
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Short>> ShortArray.dropWhileTo(result: L, predicate: (Short) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <L: List<Short>> ShortArray.takeWhileTo(result: L, predicate: (Short) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun ShortArray?.requireNoNulls() : List<Short> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun ShortArray.drop(n: Int): List<Short> {
|
||||
fun countTo(n: Int): (Short) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun ShortArray.dropWhile(predicate: (Short) -> Boolean): List<Short> = dropWhileTo(ArrayList<Short>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
@@ -175,6 +175,20 @@ public inline fun <T> Iterable<T>.makeString(separator: String = ", ", prefix: S
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
/** Returns a list containing the everything but the first elements that satisfy the given *predicate* */
|
||||
public inline fun <T, L: List<in T>> Iterable<T>.dropWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
var start = true
|
||||
for (element in this) {
|
||||
if (start && predicate(element)) {
|
||||
// ignore
|
||||
} else {
|
||||
start = false
|
||||
result.add(element)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** Returns a list containing the first elements that satisfy the given *predicate* */
|
||||
public inline fun <T, L: List<in T>> Iterable<T>.takeWhileTo(result: L, predicate: (T) -> Boolean) : L {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
|
||||
@@ -82,6 +82,26 @@ public inline fun <in T> Iterable<T?>?.requireNoNulls() : List<T> {
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing everything but the first *n* elements
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.drop(n: Int): List<T> {
|
||||
fun countTo(n: Int): (T) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt dropWhile
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.dropWhile(predicate: (T) -> Boolean): List<T> = dropWhileTo(ArrayList<T>(), predicate)
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user