computeIfAbsent method
V
computeIfAbsent(
- K key,
- V ifAbsent(
- K key
Computes a value for the given key if it is not already present in the map.
Parameters
key
: The key to compute a value forifAbsent
: The function to compute the value if the key is not present
Returns
- The computed value
Implementation
V computeIfAbsent(K key, V Function(K key) ifAbsent) {
if (containsKey(key)) {
return this[key] as V;
} else {
final V newValue = ifAbsent(key);
this[key] = newValue;
return newValue;
}
}