W3cubDocs

/Kotlin

AbstractIterator

abstract class AbstractIterator<T> : Iterator<T>

A base class to simplify implementing iterators so that implementations only have to implement computeNext to implement the iterator, calling done when the iteration is complete.

Constructors

<init>

AbstractIterator()

A base class to simplify implementing iterators so that implementations only have to implement computeNext to implement the iterator, calling done when the iteration is complete.

Functions

computeNext

abstract fun computeNext()

Computes the next item in the iterator.

done

fun done()

Sets the state to done so that the iteration terminates.

hasNext

open fun hasNext(): Boolean

Returns true if the iteration has more elements.

next

open fun next(): T

Returns the next element in the iteration.

setNext

fun setNext(value: T)

Sets the next value in the iteration, called from the computeNext function

Extension Functions

asSequence

fun <T> Iterator<T>.asSequence(): Sequence<T>

Creates a sequence that returns all elements from this iterator. The sequence is constrained to be iterated only once.

forEach

fun <T> Iterator<T>.forEach(operation: (T) -> Unit)

Performs the given operation on each element of this Iterator.

iterator

operator fun <T> Iterator<T>.iterator(): Iterator<T>

Returns the given iterator itself. This allows to use an instance of iterator in a for loop.

withIndex

fun <T> Iterator<T>.withIndex(): Iterator<IndexedValue<T>>

Returns an Iterator wrapping each value produced by this Iterator with the IndexedValue, containing value and it's index.

© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-iterator/index.html