/// <summary> /// Atomically updates an existing item /// </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> SetItem(K key, V value) { if (isnull(key)) { throw new ArgumentNullException(nameof(key)); } return(SetRoot(MapModule.SetItem(Root, key, value, Comparer <K> .Default))); }
/// <summary> /// Atomically sets a series of items using the Tuples provided. /// </summary> /// <param name="items">Items to set</param> /// <exception cref="ArgumentException">Throws ArgumentException if any of the keys aren't in the map</exception> /// <returns>New map with the items set</returns> public Map <K, V> SetItems(IEnumerable <Tuple <K, V> > items) { if (items == null) { return(this); } var self = Root; foreach (var item in items) { if (isnull(item.Item1)) { continue; } self = MapModule.SetItem(self, item.Item1, item.Item2, Comparer <K> .Default); } return(SetRoot(self)); }
/// <summary> /// Atomically sets a series of items using the KeyValuePairs provided /// </summary> /// <param name="items">Items to set</param> /// <exception cref="ArgumentException">Throws ArgumentException if any of the keys aren't in the map</exception> /// <returns>New map with the items set</returns> public Map <K, V> SetItems(IEnumerable <KeyValuePair <K, V> > items) { if (items == null) { return(this); } var self = Root; foreach (var item in items) { if (item.Key == null) { continue; } self = MapModule.SetItem(self, item.Key, item.Value, Comparer <K> .Default); } return(SetRoot(self)); }