name.remal.kotlin.collections.Iterable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Java & Kotlin tools: common
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()