internal static Behavior <T> SwitchBImpl <T, T2>(this Behavior <T2> bba)
            where T2 : Behavior <T>
        {
            return(TransactionInternal.Apply(
                       (trans1, _) =>
            {
                Lazy <T> za = bba.SampleLazyImpl().MapImpl(ba => ba.SampleImpl());
                Stream <T> @out = new Stream <T>(bba.KeepListenersAlive);
                MutableListener currentListener = new MutableListener();

                void H(TransactionInternal trans2, Behavior <T> ba)
                {
                    IListener cl = currentListener;
                    cl.Unlisten();

                    currentListener.SetListenerImpl(ba.Value(trans2).Listen(@out.Node, trans2, @out.Send, false));
                }

                IListener l1 = bba.Value(trans1).Listen(@out.Node, trans1, H, false);
                return @out.UnsafeAttachListener(l1)
                .UnsafeAttachListener(currentListener)
                .HoldLazyInternal(trans1, za);
            },
                       false));
        }
Esempio n. 2
0
        internal Stream <TResult> SnapshotImpl <T1, TResult>(Behavior <T1> b, Func <T, T1, TResult> f)
        {
            Stream <TResult> @out = new Stream <TResult>(this.KeepListenersAlive);
            IListener        l    = this.Listen(@out.Node, (trans2, a) => @out.Send(trans2, f(a, b.SampleNoTransaction())));

            return(@out.UnsafeAttachListener(l));
        }
        internal static Stream <T> SwitchSImpl <T, T2>(this Behavior <T2> bsa) where T2 : Stream <T>
        {
            return(TransactionInternal.Apply(
                       (trans1, _) =>
            {
                Stream <T> @out = new Stream <T>(bsa.KeepListenersAlive);
                MutableListener currentListener = new MutableListener();

                void HInitial(TransactionInternal trans2, Stream <T> sa)
                {
                    IListener cl = currentListener;
                    cl.Unlisten();

                    currentListener.SetListenerImpl(sa.Listen(@out.Node, trans2, @out.Send, false));
                }

                void H(TransactionInternal trans2, Stream <T> sa)
                {
                    trans2.Last(
                        () =>
                    {
                        IListener cl = currentListener;
                        cl.Unlisten();

                        currentListener.SetListenerImpl(sa.Listen(@out.Node, trans2, @out.Send, true));
                    });
                }

                trans1.Prioritized(new Node <T>(), trans2 => HInitial(trans2, bsa.SampleNoTransaction()));
                IListener l1 = bsa.Updates().Listen(new Node <T>(), trans1, H, false);
                return @out.UnsafeAttachListener(l1).UnsafeAttachListener(currentListener);
            },
                       false));
        }
Esempio n. 4
0
        internal Stream <TResult> MapImpl <TResult>(Func <T, TResult> f)
        {
            Stream <TResult> @out = new Stream <TResult>(this.KeepListenersAlive);
            IListener        l    = this.Listen(@out.Node, (trans2, a) => @out.Send(trans2, f(a)));

            return(@out.UnsafeAttachListener(l));
        }
Esempio n. 5
0
        internal Stream <T> Coalesce(TransactionInternal trans1, Func <T, T, T> f)
        {
            Stream <T> @out = new Stream <T>(this.KeepListenersAlive);
            Action <TransactionInternal, T> h = CoalesceHandler.Create(f, @out);
            IListener l = this.Listen(@out.Node, trans1, h, false);

            return(@out.UnsafeAttachListener(l));
        }
Esempio n. 6
0
        internal static Stream <T> FilterMaybeImpl <T, TMaybe>(this Stream <TMaybe> s, Action <TMaybe, Action <T> > matchSome)
        {
            Stream <T> @out = new Stream <T>(s.KeepListenersAlive);

            IListener l =
                s.Listen(
                    @out.Node,
                    (trans2, a) => matchSome(a, v => @out.Send(trans2, v)));

            return(@out.UnsafeAttachListener(l));
        }
Esempio n. 7
0
        internal Stream <T> FilterImpl(Func <T, bool> predicate)
        {
            Stream <T> @out = new Stream <T>(this.KeepListenersAlive);
            IListener  l    = this.Listen(
                @out.Node,
                (trans2, a) =>
            {
                if (predicate(a))
                {
                    @out.Send(trans2, a);
                }
            });

            return(@out.UnsafeAttachListener(l));
        }
Esempio n. 8
0
        internal static Stream <T> SplitImpl <T, TCollection>(Stream <TCollection> s)
            where TCollection : IEnumerable <T>
        {
            Stream <T> @out = new Stream <T>(s.KeepListenersAlive);
            IListener  l1   = s.Listen(
                new Node <T>(),
                (trans, aa) =>
            {
                int childIx = 0;
                foreach (T a in aa)
                {
                    trans.Split(childIx, trans1 => @out.Send(trans1, a));
                    childIx++;
                }
            });

            return(@out.UnsafeAttachListener(l1));
        }
Esempio n. 9
0
        private Stream <T> Merge(TransactionInternal trans, Stream <T> s)
        {
            Stream <T> @out  = new Stream <T>(this.KeepListenersAlive);
            Node <T>   left  = new Node <T>();
            Node <T>   right = @out.Node;

            (bool changed, Node <T> .Target nodeTarget) = left.Link(trans, (t, v) => { }, right);
            if (changed)
            {
                trans.SetNeedsRegenerating();
            }

            Action <TransactionInternal, T> h = @out.Send;
            IListener l1 = this.Listen(left, h);
            IListener l2 = s.Listen(right, h);

            return(@out.UnsafeAttachListener(l1)
                   .UnsafeAttachListener(l2)
                   .UnsafeAttachListener(ListenerInternal.CreateFromNodeAndTarget(left, nodeTarget)));
        }
Esempio n. 10
0
        internal Stream <TResult> SnapshotImpl <T1, T2, T3, T4, TResult>(
            Behavior <T1> b1,
            Behavior <T2> b2,
            Behavior <T3> b3,
            Behavior <T4> b4,
            Func <T, T1, T2, T3, T4, TResult> f)
        {
            Stream <TResult> @out = new Stream <TResult>(this.KeepListenersAlive);
            IListener        l    = this.Listen(
                @out.Node,
                (trans2, a) => @out.Send(
                    trans2,
                    f(
                        a,
                        b1.SampleNoTransaction(),
                        b2.SampleNoTransaction(),
                        b3.SampleNoTransaction(),
                        b4.SampleNoTransaction())));

            return(@out.UnsafeAttachListener(l));
        }