diff --git a/libraries/stdlib/src/kotlin/collections/IndexingIterator.kt b/libraries/stdlib/src/kotlin/collections/IndexingIterator.kt new file mode 100644 index 00000000000..07c83c8e83e --- /dev/null +++ b/libraries/stdlib/src/kotlin/collections/IndexingIterator.kt @@ -0,0 +1,26 @@ +package kotlin + +/** + * Data class representing a value from a collection or sequence, along with its index in that collection or sequence. + * + * @property value the underlying value. + * @property index the index of the value in the collection or sequence. + */ +public data class IndexedValue(public val index: Int, public val value: T) + +/** + * A wrapper over another [Iterable] (or any other object that can produce an [Iterator]) that returns + * an indexing iterator. + */ +public class IndexingIterable(private val iteratorFactory: () -> Iterator) : Iterable> { + override fun iterator(): Iterator> = IndexingIterator(iteratorFactory()) +} + +/** + * Iterator transforming original `iterator` into iterator of [IndexedValue], counting index from zero. + */ +public class IndexingIterator(private val iterator: Iterator) : Iterator> { + private var index = 0 + final override fun hasNext(): Boolean = iterator.hasNext() + final override fun next(): IndexedValue = IndexedValue(index++, iterator.next()) +} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/collections/Iterators.kt b/libraries/stdlib/src/kotlin/collections/Iterators.kt index 3ac8977e839..798aaebac4e 100644 --- a/libraries/stdlib/src/kotlin/collections/Iterators.kt +++ b/libraries/stdlib/src/kotlin/collections/Iterators.kt @@ -26,27 +26,3 @@ public inline fun Iterator.forEach(operation: (T) -> Unit) : Unit { for (element in this) operation(element) } -/** - * Data class representing a value from a collection or sequence, along with its index in that collection or sequence. - * - * @property value the underlying value. - * @property index the index of the value in the collection or sequence. - */ -public data class IndexedValue(public val index: Int, public val value: T) - -/** - * A wrapper over another [Iterable] (or any other object that can produce an [Iterator]) that returns - * an indexing iterator. - */ -public class IndexingIterable(private val iteratorFactory: () -> Iterator) : Iterable> { - override fun iterator(): Iterator> = IndexingIterator(iteratorFactory()) -} - -/** - * Iterator transforming original `iterator` into iterator of [IndexedValue], counting index from zero. - */ -public class IndexingIterator(private val iterator: Iterator) : Iterator> { - private var index = 0 - final override fun hasNext(): Boolean = iterator.hasNext() - final override fun next(): IndexedValue = IndexedValue(index++, iterator.next()) -}