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

commonMain.io.github.lyxnx.util.collection.Map.kt Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
@file:JvmName("Maps")

package io.github.lyxnx.util.collection

import kotlin.jvm.JvmName

/**
 * Returns whether this map contains [key] and all of [keys]
 */
public fun  Map.containsKeys(key: K, vararg keys: K): Boolean =
    containsKey(key) && keys.all(::containsKey)

/**
 * Returns whether this map contains all the keys given in the collection [keys]
 */
public fun  Map.containsKeys(keys: Collection): Boolean = keys.all(::containsKey)

/**
 * Returns whether this map contains [value] and all of [values]
 */
public fun  Map<*, V>.containsValues(value: V, vararg values: V): Boolean =
    containsValue(value) && values.all(::containsValue)

/**
 * Returns whether this map contains all the values given in the collection [values]
 */
public fun  Map<*, V>.containsValues(values: Collection): Boolean = values.all(::containsValue)

/**
 * Filters this map by removing all entries with a null value
 */
@Suppress("UNCHECKED_CAST")
public fun  Map.filterNotNullValues(): Map = filterValues { it != null } as Map

/**
 * Filters this map by removing all entries with a value that is not of type [V]
 */
@Suppress("UNCHECKED_CAST")
public inline fun  Map.filterValues(): Map =
    filterValues { it != null && it::class == V::class } as Map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy