simplified the library code to avoid some JS compile errors

This commit is contained in:
James Strachan
2012-06-22 14:32:48 +01:00
parent 53b59ce152
commit 0873d3a494
2 changed files with 6 additions and 10 deletions
@@ -85,13 +85,14 @@ public inline fun <in T> java.lang.Iterable<T?>?.requireNoNulls() : List<T> {
* @includeFunctionBody ../../test/CollectionTest.kt drop * @includeFunctionBody ../../test/CollectionTest.kt drop
*/ */
public inline fun <T> java.lang.Iterable<T>.drop(n: Int): List<T> { 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)) 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* * 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 * @includeFunctionBody ../../test/CollectionTest.kt take
*/ */
public inline fun <T> java.lang.Iterable<T>.take(n: Int): List<T> { 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)) 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)> { public fun <T> java.lang.Iterable<T>.withIndices() : java.lang.Iterable<#(Int, T)> {
return object : java.lang.Iterable<#(Int, T)> { return object : java.lang.Iterable<#(Int, T)> {
public override fun iterator(): java.util.Iterator<#(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()!!)
return NumberedIterator<T>(this@withIndices.iterator().sure()) as java.util.Iterator<#(Int, T)>
} }
} }
} }