Overload constructor of Composite iterator for lazy use cases

This time in the right file
This commit is contained in:
Andrey Breslav
2014-01-21 18:06:22 +04:00
parent 847d69ee2e
commit 7b61bdb9b1
+5 -4
View File
@@ -112,16 +112,17 @@ class FunctionIterator<T:Any>(val nextFunction: () -> T?): AbstractIterator<T>()
}
/** An [[Iterator]] which iterates over a number of iterators in sequence */
class CompositeIterator<T>(vararg iterators: Iterator<T>): AbstractIterator<T>() {
fun CompositeIterator<T>(vararg iterators: Iterator<T>): CompositeIterator<T> = CompositeIterator(iterators.iterator())
class CompositeIterator<T>(val iterators: Iterator<Iterator<T>>): AbstractIterator<T>() {
val iteratorsIter = iterators.iterator()
var currentIter: Iterator<T>? = null
override protected fun computeNext(): Unit {
while (true) {
if (currentIter == null) {
if (iteratorsIter.hasNext()) {
currentIter = iteratorsIter.next()
if (iterators.hasNext()) {
currentIter = iterators.next()
} else {
done()
return