kbox-android / ch.tutteli.kbox / PeekingIterator

PeekingIterator

interface PeekingIterator<out T : Any> : Iterator<T>

An Iterator which provides the peek function in addition.

Functions

peek

abstract fun peek(): T

Returns the next element without consuming it.

Extension Functions

forEachRemaining

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

Performs the given operation on each remaining element.

glue

infix fun <T> T.glue(otherArgs: Array<out T>): List<T>

Delegates to varargToList -- adds this and the otherArgs into a new List and returns it.

mapRemaining

fun <T, R> Iterator<T>.mapRemaining(transform: (T) -> R): List<R>

Maps remaining values of this Iterator with the help of the given transform functions, returns an empty list if Iterator.hasNext returns false for the first call.

mapRemainingWithCounter

fun <T, R> Iterator<T>.mapRemainingWithCounter(transform: (index: Int, T) -> R): List<R>

Maps remaining values of this Iterator with the help of the given transform functions where a counter variable is passed ot the transform function starting by 0; returns an empty list if Iterator.hasNext returns false for the first call.

toPeekingIterator

fun <T : Any> Iterator<T>.toPeekingIterator(): PeekingIterator<T>

Wraps this Iterator into a PeekingIterator and returns it.

Companion Object Extension Functions

create

fun <T : Any> PeekingIterator.Companion.create(itr: Iterator<T>): PeekingIterator<T>

Platform independent method which creates a PeekingIterator based on a given itr.

Inheritors

DefaultPeekingIterator

class DefaultPeekingIterator<out T : Any> : PeekingIterator<T>

An Iterator which provides the peek function in addition.