All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.marid.fx.extensions.StreamExtensions.kt Maven / Gradle / Ivy
package org.marid.fx.extensions
import java.util.stream.Collectors
import java.util.stream.Stream
fun Stream.toImmutableMap(key: (T) -> K, value: (T) -> V): Map =
collect(Collectors.toUnmodifiableMap(key, value))
fun Stream.toImmutableMap(key: (T) -> K, value: (T) -> V, merger: (V, V) -> V): Map =
collect(Collectors.toUnmodifiableMap(key, value, merger))
fun > Stream.toImmutableMap(): Map =
collect(Collectors.toUnmodifiableMap({ it.first }, { it.second }))
fun > Stream.toImmutableMap(merger: (V, V) -> V): Map =
collect(Collectors.toUnmodifiableMap({ it.first }, { it.second }, { a, b -> merger(a, b) }))
fun Stream.toMap(key: (T) -> K, value: (T) -> V): MutableMap =
collect(Collectors.toMap(key, value))
fun > Stream.toMap(): Map =
collect(Collectors.toMap({ it.first }, { it.second }))
fun > Stream.toMap(merger: (V, V) -> V): Map =
collect(Collectors.toMap({ it.first }, { it.second }, { a, b -> merger(a, b) }))
fun Stream.toMap(key: (T) -> K, value: (T) -> V, merger: (V, V) -> V): MutableMap =
collect(Collectors.toMap(key, value, merger))
fun > Stream.toCustomMap(key: (T) -> K, value: (T) -> V, merger: (V, V) -> V, factory: () -> M): M =
collect(Collectors.toMap(key, value, merger, factory))
fun , M : MutableMap> Stream.toCustomMap(merger: (V, V) -> V, factory: () -> M): M =
collect(Collectors.toMap({ it.first }, { it.second }, merger, factory))
fun Stream.toImmutableList(): List = collect(Collectors.toUnmodifiableList())
fun Stream.toList(): MutableList = collect(Collectors.toList())
fun > Stream.toCollection(factory: () -> C): C = collect(Collectors.toCollection(factory))
inline fun Stream.toTypedArray(): Array = toArray { n -> arrayOfNulls(n) }