示例#1
0
 static void RemoveLocalRegisteredById(ProcessId pid)
 {
     lock (regsync)
     {
         var names = registeredProcessIds.Find(pid).IfNone(Set.empty <ProcessName>());
         names.Iter(name =>
                    registeredProcessNames = registeredProcessNames.SetItem(name, registeredProcessNames[name].Remove(pid))
                    );
         registeredProcessIds = registeredProcessIds.Remove(pid);
     }
 }
示例#2
0
        public static Map <A, Map <B, Map <C, Map <D, V> > > > TrySetItemT <A, B, C, D, V>(this Map <A, Map <B, Map <C, Map <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, Func <V, V> Some)
        {
            var a = map.Find(aKey);

            if (a.IsNone)
            {
                return(map);
            }
            var av = a.Value;

            return(map.SetItem(aKey, av.TrySetItemT(bKey, cKey, dKey, Some)));
        }
示例#3
0
        public static Map <A, Map <B, V> > TrySetItemT <A, B, V>(this Map <A, Map <B, V> > map, A aKey, B bKey, V value)
        {
            var a = map.Find(aKey);

            if (a.IsNone)
            {
                return(map);
            }
            var av = a.Value;

            return(map.SetItem(aKey, av.TrySetItem(bKey, value)));
        }
示例#4
0
        public static Map <A, Map <B, Map <C, Map <D, V> > > > SetItemT <A, B, C, D, V>(this Map <A, Map <B, Map <C, Map <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, Func <V, V> Some)
        {
            var a = map.Find(aKey);

            if (a.IsNone)
            {
                throw new ArgumentException("Key not found in Map");
            }
            var av = a.Value;

            return(map.SetItem(aKey, av.SetItemT(bKey, cKey, dKey, Some)));
        }
示例#5
0
        public static Map <A, Map <B, V> > SetItemT <A, B, V>(this Map <A, Map <B, V> > map, A aKey, B bKey, V value)
        {
            var a = map.Find(aKey);

            if (a.IsNone)
            {
                throw new ArgumentException("Key not found in Map");
            }
            var av = a.Value;

            return(map.SetItem(aKey, av.SetItem(bKey, value)));
        }
示例#6
0
        static void RemoveLocalRegisteredByName(ProcessName name)
        {
            lock (regsync)
            {
                var pids = registeredProcessNames.Find(name).IfNone(Set.empty <ProcessId>());

                pids.Iter(pid =>
                          registeredProcessIds = registeredProcessIds.SetItem(pid, registeredProcessIds[pid].Remove(name))
                          );
                registeredProcessNames = registeredProcessNames.Remove(name);
            }
        }
示例#7
0
        public static Map <A, Map <B, Map <C, D> > > Remove <A, B, C, D>(this Map <A, Map <B, Map <C, D> > > self, A aKey, B bKey, C cKey)
        {
            var b = self.Find(aKey);

            if (b.IsSome)
            {
                var c = b.Value.Find(bKey);
                if (c.IsSome)
                {
                    var cv = c.Value.Remove(cKey);
                    if (cv.Count() == 0)
                    {
                        var bv = b.Value.Remove(bKey);
                        if (b.Value.Count() == 0)
                        {
                            return(self.Remove(aKey));
                        }
                        else
                        {
                            return(self.SetItem(aKey, bv));
                        }
                    }
                    else
                    {
                        return(self.SetItem(aKey, b.Value.SetItem(bKey, cv)));
                    }
                }
                else
                {
                    return(self);
                }
            }
            else
            {
                return(self);
            }
        }
示例#8
0
        public static Map <A, Map <B, C> > Remove <A, B, C>(this Map <A, Map <B, C> > self, A outerKey, B innerKey)
        {
            var b = self.Find(outerKey);

            if (b.IsSome)
            {
                var bv = b.Value.Remove(innerKey);
                if (bv.Count() == 0)
                {
                    return(self.Remove(outerKey));
                }
                else
                {
                    return(self.SetItem(outerKey, bv));
                }
            }
            else
            {
                return(self);
            }
        }
示例#9
0
 /// <summary>
 /// Retrieve a value from the map by key, map it to a new value,
 /// put it back.
 /// </summary>
 /// <param name="key">Key to find</param>
 /// <returns>New map with the mapped value</returns>
 public static Map <K, V> setItem <K, V>(Map <K, V> map, K key, Func <V, V> mapper) =>
 map.SetItem(key, mapper);
示例#10
0
 /// <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 static Map <K, V> setItem <K, V>(Map <K, V> map, K key, V value) =>
 map.SetItem(key, value);