commonMain.com.bkahlert.kommons.iterators.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kommons-core-jvm Show documentation
Show all versions of kommons-core-jvm Show documentation
Kommons Core is a Kotlin Multiplatform Library that offers shared features for all Kommons modules.
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