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

name.remal.kotlin.sequences.Sequence.kt Maven / Gradle / Ivy

package name.remal

import java.util.*

fun  Sequence.toMutableMap(keyExtractor: (value: V) -> K): MutableMap = mutableMapOf().also {
    for (value in this) {
        val key = keyExtractor(value)
        it[key] = value
    }
}

fun  Sequence.toMap(keyExtractor: (value: V) -> K): Map = toMutableMap(keyExtractor).toMap()

fun  Sequence.toHashMap(keyExtractor: (value: V) -> K): MutableMap = hashMapOf().also {
    for (value in this) {
        val key = keyExtractor(value)
        it[key] = value
    }
}

fun > Sequence.toSortedMap(keyExtractor: (value: V) -> K): SortedMap = sortedMapOf().also {
    for (value in this) {
        val key = keyExtractor(value)
        it[key] = value
    }
}


fun  Sequence.toStream() = iterator().asStream()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy