Add samples for iterator-related extensions (KT-20357)
This commit is contained in:
committed by
Ilya Gorbunov
parent
94f77c773c
commit
4d13ea89b2
@@ -5,6 +5,7 @@ package kotlin.collections
|
||||
|
||||
/**
|
||||
* Creates an [Iterator] for an [Enumeration], allowing to use it in `for` loops.
|
||||
* @sample samples.collections.Iterators.iteratorForEnumeration
|
||||
*/
|
||||
@kotlin.jvm.JvmVersion
|
||||
public operator fun <T> java.util.Enumeration<T>.iterator(): Iterator<T> = object : Iterator<T> {
|
||||
@@ -15,6 +16,7 @@ public operator fun <T> java.util.Enumeration<T>.iterator(): Iterator<T> = objec
|
||||
|
||||
/**
|
||||
* Returns the given iterator itself. This allows to use an instance of iterator in a `for` loop.
|
||||
* @sample samples.collections.Iterators.iterator
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun <T> Iterator<T>.iterator(): Iterator<T> = this
|
||||
@@ -22,11 +24,13 @@ public inline operator fun <T> Iterator<T>.iterator(): Iterator<T> = this
|
||||
/**
|
||||
* Returns an [Iterator] wrapping each value produced by this [Iterator] with the [IndexedValue],
|
||||
* containing value and it's index.
|
||||
* @sample samples.collections.Iterators.withIndexIterator
|
||||
*/
|
||||
public fun <T> Iterator<T>.withIndex(): Iterator<IndexedValue<T>> = IndexingIterator(this)
|
||||
|
||||
/**
|
||||
* Performs the given [operation] on each element of this [Iterator].
|
||||
* @sample samples.collections.Iterators.forEachIterator
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.forEach(operation: (T) -> Unit) : Unit {
|
||||
for (element in this) operation(element)
|
||||
|
||||
Reference in New Issue
Block a user