addAll method
The entries of the given imap
will be added to the original map.
Note: imap
entries that already exist in the original map will overwrite
those of the original map.
If the current map is sorted, then if keepOrder
is false
(the default),
those entries that already exist will go to the end of the new map. If
keepOrder
is true
, those entries that already exist will be replaced in
place.
If the current map is NOT sorted, the keepOrder
parameter is ignored.
Note: This will NOT sort anything.
Implementation
M<K, V> addAll(IMap<K, V> imap, {bool keepOrder = false}) {
if (keepOrder) {
Map<K, V> map = Map.fromEntries(entries.followedBy(imap.entries));
return MFlat<K, V>.unsafe(map);
}
//
else {
// We want the entries being added to overwrite those of the original add.
// So we have to remove the entries that are already present in the second map.
Map<K, V> firstMap =
ListMap.fromEntries(entries.where((entry) => !imap.containsKey(entry.key)));
M<K, V> firstM = MFlat<K, V>.unsafe(firstMap);
return MAddAll<K, V>.unsafe(firstM, imap._m);
}
}