update method

V update (
  1. K key,
  2. V update(
    1. V value
    ),
  3. {V ifAbsent( )}
)
override

Updates the value for the provided key.

Returns the new value associated with the key.

If the key is present, invokes update with the current value and stores the new value in the map.

If the key is not present and ifAbsent is provided, calls ifAbsent and adds the key with the returned value to the map.

If the key is not present, ifAbsent must be provided.

Implementation

V update(K key, V update(V value), {V Function()? ifAbsent}) {
  if (this.containsKey(key)) {
    return this[key] = update(this[key] as V);
  }
  if (ifAbsent != null) {
    return this[key] = ifAbsent();
  }
  throw ArgumentError.value(key, "key", "Key not in map.");
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-collection/MapMixin/update.html