kotlin.IteratorsJVM.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-stdlib Show documentation
Show all versions of kotlin-stdlib Show documentation
Kotlin Standard Library for JVM
package kotlin
import kotlin.support.*
/** Returns an iterator over elements that are instances of a given type *R* which is a subclass of *T* */
public fun Iterator.filterIsInstance(klass: Class): Iterator = FilterIsIterator(this, klass)
private class FilterIsIterator(val iterator : Iterator, val klass: Class) : AbstractIterator() {
override protected fun computeNext(): Unit {
while (iterator.hasNext()) {
val next = iterator.next()
if (klass.isInstance(next)) {
setNext(next as R)
return
}
}
done()
}
}