name.remal.arrays.kt Maven / Gradle / Ivy
package name.remal
import java.util.Arrays
import java.util.SortedMap
import java.util.stream.Stream
fun Array.stream(): Stream = Arrays.stream(this)
fun Array.toMutableMap(keyExtractor: (value: V) -> K): MutableMap = mutableMapOf().also {
for (value in this) {
val key = keyExtractor(value)
it[key] = value
}
}
fun Array.toMap(keyExtractor: (value: V) -> K): Map = toMutableMap(keyExtractor).toMap()
fun Array.toHashMap(keyExtractor: (value: V) -> K): MutableMap = hashMapOf().also {
for (value in this) {
val key = keyExtractor(value)
it[key] = value
}
}
fun > Array.toSortedMap(keyExtractor: (value: V) -> K): SortedMap = sortedMapOf().also {
for (value in this) {
val key = keyExtractor(value)
it[key] = value
}
}