name.remal.kotlin.collections.Map.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.Collections.synchronizedMap
import java.util.stream.Stream
fun > M?.nullIfEmpty(): M? = nullIf(Map<*, *>::isEmpty)
fun Map.asSynchronized(): Map = synchronizedMap(this)
inline fun Map.forEachIndexed(action: (index: Int, key: K, value: V) -> Unit) {
this.entries.forEachIndexed { index, entry ->
action(index, entry.key, entry.value)
}
}
fun Map.filterNotNullKeys(): Map = filterKeys { it != null }.uncheckedCast()
fun Map.filterNotNullValues(): Map = filterValues { it != null }.uncheckedCast()
fun Map.stream(): Stream> = entries.stream()