Make stdlib functions dependent on reified is checks available in JS.

#KT-11346 Fixed
This commit is contained in:
Ilya Gorbunov
2016-04-25 19:18:35 +03:00
parent a5fd95c7d9
commit 409094f0f7
10 changed files with 232 additions and 120 deletions
+15 -17
View File
@@ -3233,6 +3233,21 @@ public inline fun <C : MutableCollection<in Char>> CharArray.filterIndexedTo(des
return destination
}
/**
* Returns a list containing all elements that are instances of specified type parameter R.
*/
public inline fun <reified R> Array<*>.filterIsInstance(): List<@kotlin.internal.NoInfer R> {
return filterIsInstanceTo(ArrayList<R>())
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
public inline fun <reified R, C : MutableCollection<in R>> Array<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
@@ -12583,14 +12598,6 @@ public fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int = size
Arrays.fill(this, fromIndex, toIndex, element)
}
/**
* Returns a list containing all elements that are instances of specified type parameter R.
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R> Array<*>.filterIsInstance(): List<@kotlin.internal.NoInfer R> {
return filterIsInstanceTo(ArrayList<R>())
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
@@ -12599,15 +12606,6 @@ public fun <R> Array<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass)
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R, C : MutableCollection<in R>> Array<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
+15 -17
View File
@@ -626,6 +626,21 @@ public inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterIndexedTo(d
return destination
}
/**
* Returns a list containing all elements that are instances of specified type parameter R.
*/
public inline fun <reified R> Iterable<*>.filterIsInstance(): List<@kotlin.internal.NoInfer R> {
return filterIsInstanceTo(ArrayList<R>())
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
public inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
@@ -1871,14 +1886,6 @@ public fun <T> Iterable<T>.asSequence(): Sequence<T> {
return Sequence { this.iterator() }
}
/**
* Returns a list containing all elements that are instances of specified type parameter R.
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R> Iterable<*>.filterIsInstance(): List<@kotlin.internal.NoInfer R> {
return filterIsInstanceTo(ArrayList<R>())
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
@@ -1887,15 +1894,6 @@ public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass)
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
+16 -18
View File
@@ -332,6 +332,22 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterIndexedTo(d
return destination
}
/**
* Returns a sequence containing all elements that are instances of specified type parameter R.
*/
public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.internal.NoInfer R> {
@Suppress("UNCHECKED_CAST")
return filter { it is R } as Sequence<R>
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Returns a sequence containing all elements not matching the given [predicate].
*/
@@ -1176,15 +1192,6 @@ public inline fun <T> Sequence<T>.asSequence(): Sequence<T> {
return this
}
/**
* Returns a sequence containing all elements that are instances of specified type parameter R.
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.internal.NoInfer R> {
@Suppress("UNCHECKED_CAST")
return filter { it is R } as Sequence<R>
}
/**
* Returns a sequence containing all elements that are instances of specified class.
*/
@@ -1194,15 +1201,6 @@ public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
return filter { klass.isInstance(it) } as Sequence<R>
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
@kotlin.jvm.JvmVersion
public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsInstanceTo(destination: C): C {
for (element in this) if (element is R) destination.add(element)
return destination
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/