update method

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

Updates the value for the provided key.

If the key/value pair is new or changed then a MapUpdate is sent to attached streams.

Implementation

@override
V? update(
  K key,
  V? Function(V? value) update, {
  V? Function()? ifAbsent,
}) {
  final v = this[key];

  if (v == null) {
    if (ifAbsent == null) {
      throw ArgumentError.notNull(
          'ifAbsent cannot be null if key does not exist on map');
    } else {
      final absentV = ifAbsent();
      this[key] = absentV;
      return absentV;
    }
  }
  final updatedV = update(v);
  this[key] = updatedV;
  return updatedV;
}