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

name.remal.kotlin.collections.Iterable.kt Maven / Gradle / Ivy

There is a newer version: 1.26.147
Show newest version
package name.remal

import java.util.*

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

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

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

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


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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy