예제 #1
0
        internal static Action <TransactionInternal, T> Create <T>(Func <T, T, T> f, Stream <T> @out)
        {
            bool accumValid = false;
            T    accum      = default(T);

            return((trans1, a) =>
            {
                if (accumValid)
                {
                    accum = f(accum, a);
                }
                else
                {
                    accum = a;
                    accumValid = true;

                    trans1.Prioritized(
                        @out.Node,
                        trans2 =>
                    {
                        // ReSharper disable once AccessToModifiedClosure
                        @out.Send(trans2, accum);
                        accumValid = false;
                        accum = default(T);
                    });
                }
            });
        }
예제 #2
0
파일: Stream.cs 프로젝트: stjordanis/sodium
        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));
        }
예제 #3
0
파일: Stream.cs 프로젝트: stjordanis/sodium
        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));
        }
예제 #4
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));
        }
예제 #5
0
파일: Stream.cs 프로젝트: stjordanis/sodium
        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));
        }
예제 #6
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));
        }
예제 #7
0
파일: Stream.cs 프로젝트: stjordanis/sodium
        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));
        }