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

org.marid.fx.extensions.StreamExtensions.kt Maven / Gradle / Ivy

There is a newer version: 0.9.8.10
Show newest version
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) }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy