Exemple #1
0
        public Option <V> Find(K key)
        {
            if (isnull(key))
            {
                return(None);
            }
            var eq = EqualityComparer <K> .Default;

            return(hashTable.Find(key.GetHashCode())
                   .Bind(bucket => bucket.Find(x => eq.Equals(x.Key, key))
                         .Map(x => x.Value)));
        }
Exemple #2
0
        public static Unit DispatchTerminate(ProcessId terminating)
        {
            watchers.Find(terminating).IfSome(ws =>
            {
                var term = new TerminatedMessage(terminating);
                ws.Iter(w =>
                {
                    try
                    {
                        TellUserControl(w, term);
                    }
                    catch (Exception e)
                    {
                        Process.logErr(e);
                    }
                });
            });

            watchers = watchers.Remove(terminating);

            watchings.Find(terminating).IfSome(ws => ws.Iter(w => GetDispatcher(w).UnWatch(terminating)));
            watchings.Remove(terminating);

            return(unit);
        }
 public static F Find <A, B, C, D, E, F>(this Map <A, Map <B, Map <C, Map <D, E> > > > self, A aKey, B bKey, C cKey, D dKey, Func <E, F> Some, Func <F> None) =>
 self.Find(aKey,
           b => b.Find(bKey,
                       c => c.Find(cKey,
                                   d => d.Find(dKey, Some, None),
                                   None),
                       None),
           None);
Exemple #4
0
 /// <summary>
 /// Get a session from local state or from the cluster.  If it's expired locally
 /// it will double check if it's been updated remotely.
 /// </summary>
 /// <param name="state">State</param>
 /// <param name="sessionId">Session to get</param>
 /// <returns>Optional session</returns>
 public static Option <Session> GetSession(Map <string, Session> state, string sessionId) =>
 state.Find(sessionId)
 .Map(
     session =>
     SomeIfValid(session).Match(
         Some: s => Some(s),
         None: () => GetClusterSession(sessionId)))
 .IfNone(None);
Exemple #5
0
        public Option <T> Find(T key)
        {
            if (isnull(key))
            {
                return(None);
            }
            var eq = EqualityComparer <T> .Default;

            return(hashTable.Find(key.GetHashCode())
                   .Bind(bucket => bucket.Find(x => eq.Equals(x, key))));
        }
Exemple #6
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);
     }
 }
        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)));
        }
        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)));
        }
        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)));
        }
        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)));
        }
        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);
            }
        }
        static MethodInfo DeserialiseFunc(Type type)
        {
            var name   = type.FullName;
            var result = funcs.Find(name);

            if (result.IsSome)
            {
                return(result.LiftUnsafe());
            }

            var func = typeof(JsonConvert).GetTypeInfo()
                       .GetDeclaredMethods("DeserializeObject")
                       .Filter(m => m.IsGenericMethod)
                       .Filter(m => m.GetParameters().Length == 1)
                       .Head()
                       .MakeGenericMethod(type);

            // No locks because we don't really care if it's done
            // more than once, but we do care about locking unnecessarily.
            funcs = funcs.AddOrUpdate(name, func);
            return(func);
        }
        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);
            }
        }
 public static Option <D> Find <A, B, C, D>(this Map <A, Map <B, Map <C, D> > > self, A aKey, B bKey, C cKey) =>
 self.Find(aKey, b => b.Find(bKey, c => c.Find(cKey), () => None), () => None);
Exemple #15
0
 public State MapMetadatum(string sid, Func <object, object> map) =>
 Metadata.Find(sid,
               Some: s => SetMetadatum(sid, map(s)),
               None: () => this
               );
Exemple #16
0
 public State MapSession(string sid, Func <Session, Session> map) =>
 Sessions.Find(sid,
               Some: s => SetSession(sid, map(s)),
               None: () => this
               );
Exemple #17
0
 public static Set <ProcessId> GetLocalRegistered(ProcessName name) =>
 registeredProcessNames
 .Find(name)
 .IfNone(Set.empty <ProcessId>());
Exemple #18
0
 /// <summary>
 /// Retrieve a value from the map by key and pattern match the
 /// result.
 /// </summary>
 /// <param name="key">Key to find</param>
 /// <returns>Found value</returns>
 public static R find <K, V, R>(Map <K, V> map, K key, Func <V, R> Some, Func <R> None) =>
 map.Find(key, Some, None);
Exemple #19
0
 /// <summary>
 /// Retrieve a value from the map by key
 /// </summary>
 /// <param name="key">Key to find</param>
 /// <returns>Found value</returns>
 public static Option <V> find <K, V>(Map <K, V> map, K key) =>
 map.Find(key);
Exemple #20
0
 public Unit RemoveSubscription(ProcessId pid)
 {
     subs.Find(pid.Path).IfSome(x => x.Dispose());
     subs = subs.Remove(pid.Path);
     return(unit);
 }
 public static Option <C> Find <A, B, C>(this Map <A, Map <B, C> > self, A outerKey, B innerKey) =>
 self.Find(outerKey, b => b.Find(innerKey), () => None);
 public static E Find <A, B, C, D, E>(this Map <A, Map <B, Map <C, D> > > self, A aKey, B bKey, C cKey, Func <D, E> Some, Func <E> None) =>
 self.Find(aKey,
           b => b.Find(bKey,
                       c => c.Find(cKey, Some, None),
                       None),
           None);
 public static D Find <A, B, C, D>(this Map <A, Map <B, C> > self, A outerKey, B innerKey, Func <C, D> Some, Func <D> None) =>
 self.Find(outerKey, b => b.Find(innerKey, Some, None), None);
Exemple #24
0
 public static Func <ProcessId, IEnumerable <ProcessId> > GetDispatcherFunc(ProcessName name) =>
 dispatchers.Find(name,
                  Some: x => x,
                  None: () => (ProcessId Id) => (new ProcessId[0]).AsEnumerable()
                  );