simplified the library code to avoid some JS compile errors
This commit is contained in:
@@ -85,13 +85,14 @@ public inline fun <in T> java.lang.Iterable<T?>?.requireNoNulls() : List<T> {
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt drop
|
||||
*/
|
||||
public inline fun <T> java.lang.Iterable<T>.drop(n: Int): List<T> {
|
||||
fun countTo(n: Int): (T) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return dropWhile(countTo(n))
|
||||
}
|
||||
|
||||
private fun <T> countTo(n: Int): (T) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the everything but the first elements that satisfy the given *predicate*
|
||||
*
|
||||
@@ -105,10 +106,6 @@ public inline fun <T> java.lang.Iterable<T>.dropWhile(predicate: (T) -> Boolean)
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt take
|
||||
*/
|
||||
public inline fun <T> java.lang.Iterable<T>.take(n: Int): List<T> {
|
||||
fun countTo(n: Int): (T) -> Boolean {
|
||||
var count = 0
|
||||
return { ++count; count <= n }
|
||||
}
|
||||
return takeWhile(countTo(n))
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ public fun <T> java.lang.Iterable<T>.contains(item : T) : Boolean {
|
||||
public fun <T> java.lang.Iterable<T>.withIndices() : java.lang.Iterable<#(Int, T)> {
|
||||
return object : java.lang.Iterable<#(Int, T)> {
|
||||
public override fun iterator(): java.util.Iterator<#(Int, T)> {
|
||||
// TODO explicit typecast as a workaround for KT-1457, should be removed when it is fixed
|
||||
return NumberedIterator<T>(this@withIndices.iterator().sure()) as java.util.Iterator<#(Int, T)>
|
||||
return NumberedIterator<T>(this@withIndices.iterator()!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user