/// <summary> /// Atomically updates an existing item, unless it doesn't exist, in which case /// it is ignored /// </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 value is null</exception> /// <returns>New Map with the item added</returns> public Map <K, V> TrySetItem(K key, V value) { if (isnull(key)) { return(this); } return(SetRoot(MapModule.TrySetItem(Root, key, value, Comparer <K> .Default))); }
/// <summary> /// Atomically sets a series of items using the Tuples provided If any of the /// items don't exist then they're silently ignored. /// </summary> /// <param name="items">Items to set</param> /// <returns>New map with the items set</returns> public Map <K, V> TrySetItems(IEnumerable <Tuple <K, V> > items) { var self = Root; foreach (var item in items) { if (isnull(item.Item1)) { continue; } self = MapModule.TrySetItem(self, item.Item1, item.Item2, Comparer <K> .Default); } return(SetRoot(self)); }
/// <summary> /// Atomically sets a series of items using the KeyValuePairs provided. If any of the /// items don't exist then they're silently ignored. /// </summary> /// <param name="items">Items to set</param> /// <returns>New map with the items set</returns> public Map <K, V> TrySetItems(IEnumerable <KeyValuePair <K, V> > items) { var self = Root; foreach (var item in items) { if (item.Key == null) { continue; } self = MapModule.TrySetItem(self, item.Key, item.Value, Comparer <K> .Default); } return(SetRoot(self)); }