internal static Behavior <TResult> LiftBehaviorsImpl <T, T2, TResult>(
     this IReadOnlyCollection <T2> b,
     Func <IReadOnlyList <T>, TResult> f)
     where T2 : Behavior <T>
 {
     return(TransactionInternal.Apply(
                (trans1, _) =>
     {
         Stream <Action <T[]> > @out = new Stream <Action <T[]> >(
             new FanOutKeepListenersAlive(b.Select(behavior => behavior.KeepListenersAlive)));
         Lazy <TResult> initialValue =
             new Lazy <TResult>(() => f(b.Select(behavior => behavior.SampleNoTransaction()).ToArray()));
         IReadOnlyList <IListener> listeners = b.Select(
             (behavior, i) => behavior.Updates()
             .Listen(
                 @out.Node,
                 trans1,
                 (trans2, v) => @out.Send(trans2, vv => vv[i] = v),
                 false))
                                               .ToArray();
         return @out.Coalesce(trans1, (x, y) => x + y)
         .MapImpl(
             a =>
         {
             T[] values = b.Select(behavior => behavior.SampleNoTransaction()).ToArray();
             a(values);
             return f(values);
         })
         .UnsafeAttachListener(ListenerInternal.CreateCompositeImpl(listeners))
         .HoldLazyInternal(trans1, initialValue);
     },
                false));
 }
示例#2
0
        public Cleanup(Action cleanup)
        {
            Stream <UnitInternal> stream = StreamInternal.NeverImpl <UnitInternal>();

            stream.AttachListenerImpl(ListenerInternal.CreateFromAction(cleanup));

            this.stream = stream;
        }
示例#3
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)));
        }
示例#4
0
 public static IStrongListener CreateStrongComposite(IReadOnlyList <IStrongListener> listeners) =>
 ListenerInternal.CreateStrongCompositeImpl(listeners);
示例#5
0
 public static IWeakListener CreateWeakComposite(IReadOnlyList <IWeakListener> listeners) =>
 ListenerInternal.CreateWeakCompositeImpl(listeners);