addAll method

IMap<K, V> addAll(
  1. IMap<K, V> imap, {
  2. bool keepOrder = false,
})

Returns a new map containing the current map plus the ones in the given imap.

Note: imap entries that already exist in the original map will overwrite those of the original map.

  • If keepOrder is false (the default), those entries that already exist will be replaced at the end of the new map.
  • If keepOrder is true, the entries which already exist will be replaced at their current position.

Note: keepOrder only makes sense if your map is NOT ordered, that is ConfigMap.sort == false.

Implementation

IMap<K, V> addAll(IMap<K, V> imap, {bool keepOrder = false}) {
  IMap<K, V> result;
  result = config.sort
      ? IMap._unsafe(MFlat.fromEntries(_m.entries.followedBy(imap.entries), config: config),
          config: config)
      : IMap<K, V>._unsafe(_m.addAll(imap, keepOrder: keepOrder), config: config);

  // A map created with `addAll` has a larger counter than both its source
  // maps. This improves the order in which maps are flushed.
  // If the outer map is used, it will be flushed before the source maps.
  // If the source maps are not used directly, they will not flush
  // unnecessarily, and also may be garbage collected.
  result._counter = max(_counter, ((imap is IMap<K, V>) ? imap._counter : 0));
  result._count();

  return result;
}