/// <summary> /// Atomically adds a new item to the map. /// If the key already exists, the new item replaces it. /// </summary> /// <remarks>Null is not allowed for a Key or a Value</remarks> /// <param name="key">Key</param> /// <param name="value">Value</param> /// <exception cref="ArgumentNullException">Throws ArgumentNullException the key or value are null</exception> /// <returns>New Map with the item added</returns> public Map <K, V> AddOrUpdate(K key, V value) { if (isnull(key)) { throw new ArgumentNullException(nameof(key)); } return(SetRoot(MapModule.AddOrUpdate(Root, key, value, Comparer <K> .Default))); }
/// <summary> /// Atomically adds a range of items to the map. If any of the keys exist already /// then they're replaced. /// </summary> /// <remarks>Null is not allowed for a Key or a Value</remarks> /// <param name="range">Range of KeyValuePairs to add</param> /// <exception cref="ArgumentNullException">Throws ArgumentNullException the keys or values are null</exception> /// <returns>New Map with the items added</returns> public Map <K, V> AddOrUpdateRange(IEnumerable <KeyValuePair <K, V> > range) { if (range == null) { return(this); } var self = Root; foreach (var item in range) { if (isnull(item.Key)) { throw new ArgumentNullException(nameof(item.Key)); } self = MapModule.AddOrUpdate(self, item.Key, item.Value, Comparer <K> .Default); } return(SetRoot(self)); }