MapExtensions<K, V> extension

Common Map extensions

on

Methods

all(bool predicate(K key, V value)) bool

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

Returns true if all entries satisfy the predicate.
any(bool predicate(K key, V value)) bool

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

Returns true if any entry satisfies the predicate.
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.
mapKeys<K2>(K2 transform(K key, V value)) Map<K2, V>

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

Transforms the keys of the map.
mapValues<V2>(V2 transform(K key, V value)) Map<K, V2>

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

Transforms the values of the map.
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.
omit(Iterable<K> keys) Map<K, V>

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

Returns a new map containing all entries except those for the given keys.
pick(Iterable<K> keys) Map<K, V>

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

Returns a new map containing only the entries for the given keys.
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.