MapExtensions<K, V> extension

Common Map extensions

on

Methods

filterKeys(bool predicate(K key)) Map<K, V>

Available on Map<K, V>, provided by the MapExtensions extension

Filters the map based on a condition applied to its keys.
filterValues(bool predicate(V value)) Map<K, V>

Available on Map<K, V>, provided by the MapExtensions extension

Filters the map based on a condition applied to its values.
getOrDefault(K key, V defaultValue) → V?

Available on Map<K, V>, provided by the MapExtensions extension

Retrieves the value for the specified key from the map. If the key does not exist, returns the provided defaultValue.
getOrNull(K key) → V?

Available on Map<K, V>, provided by the MapExtensions extension

Retrieves the value for the specified key from the map. If the key does not exist, returns null.
invert() Map<V, K>

Available on Map<K, V>, provided by the MapExtensions extension

Inverts the map by swapping its keys and values. Assumes that the values are unique.
merge(Map<K, V> other, V resolve(V v1, V v2)?) Map<K, V>

Available on Map<K, V>, provided by the MapExtensions extension

Merges this map with another other map. For duplicate keys, resolve determines the final value.
toJsonString() String

Available on Map<K, V>, provided by the MapExtensions extension

Converts the map to a JSON string.
toJsonStringWithIndent([int spaces = 2]) String

Available on Map<K, V>, provided by the MapExtensions extension

Converts the map to a formatted JSON string, with specified indentation.