All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.IteratorsJVM.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
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()
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy