Ejemplo n.º 1
0
 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));
 }