All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.bkahlert.kommons.iterators.kt Maven / Gradle / Ivy

Go to download

Kommons Core is a Kotlin Multiplatform Library that offers shared features for all Kommons modules.

There is a newer version: 2.8.0
Show newest version
package com.bkahlert.kommons

/** Returns a [List] containing all elements. */
public fun  Iterator.toList(): List = asSequence().toList()

/**
 * Returns an iterator yielding the results of applying the given [transform] function
 * to each element in the original iterator.
 */
public fun  Iterator.map(transform: (T) -> R): Iterator =
    object : Iterator {
        override fun hasNext(): Boolean = [email protected]()
        override fun next(): R = transform([email protected]())
    }

/**
 * Returns an iterator that yield ranges with each element ranging from the `predecessor+1..current-1`
 * and the first element starting with the specified [start].
 */
public fun Iterator.mapToRanges(start: Int = 0): Iterator {
    var prev = start
    return map { prev until it.also { prev = it } }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy