Ejemplo n.º 1
0
        /// <summary>
        /// Transform this <see cref="Flow{TIn,TOut,TMat}"/> by appending the given processing steps.
        /// The <paramref name="combine"/> function is used to compose the materialized values of this flow and that
        /// flow into the materialized value of the resulting Flow.
        /// </summary>
        public Flow <TIn, TOut2, TMat3> ViaMaterialized <TOut2, TMat2, TMat3>(IGraph <FlowShape <TOut, TOut2>, TMat2> flow,
                                                                              Func <TMat, TMat2, TMat3> combine)
        {
            if (IsIdentity)
            {
                var m = flow.Module;
                StreamLayout.IMaterializedValueNode materializedValueNode;

                if (Keep.IsLeft(combine))
                {
                    if (IgnorableMaterializedValueComposites.Apply(m))
                    {
                        materializedValueNode = StreamLayout.Ignore.Instance;
                    }
                    else
                    {
                        materializedValueNode = new StreamLayout.Transform(_ => NotUsed.Instance,
                                                                           new StreamLayout.Atomic(m));
                    }
                }
                else
                {
                    materializedValueNode = new StreamLayout.Combine((o, o1) => combine((TMat)o, (TMat2)o1),
                                                                     StreamLayout.Ignore.Instance, new StreamLayout.Atomic(m));
                }

                return
                    (new Flow <TIn, TOut2, TMat3>(new CompositeModule(ImmutableArray <IModule> .Empty.Add(m), m.Shape,
                                                                      ImmutableDictionary <OutPort, InPort> .Empty, ImmutableDictionary <InPort, OutPort> .Empty,
                                                                      materializedValueNode, Attributes.None)));
            }

            var copy = flow.Module.CarbonCopy();

            return(new Flow <TIn, TOut2, TMat3>(Module
                                                .Fuse(copy, Shape.Outlet, copy.Shape.Inlets.First(), combine)
                                                .ReplaceShape(new FlowShape <TIn, TOut2>(Shape.Inlet, (Outlet <TOut2>)copy.Shape.Outlets.First()))));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transform this <see cref="Source{TOut,TMat}"/> by appending the given processing steps.
        /// The <paramref name="combine"/> function is used to compose the materialized values of this flow and that
        /// flow into the materialized value of the resulting Flow.
        /// </summary>
        /// <typeparam name="TOut2">TBD</typeparam>
        /// <typeparam name="TMat2">TBD</typeparam>
        /// <typeparam name="TMat3">TBD</typeparam>
        /// <param name="flow">TBD</param>
        /// <param name="combine">TBD</param>
        /// <returns>TBD</returns>
        public Source <TOut2, TMat3> ViaMaterialized <TOut2, TMat2, TMat3>(IGraph <FlowShape <TOut, TOut2>, TMat2> flow, Func <TMat, TMat2, TMat3> combine)
        {
            if (flow.Module == GraphStages.Identity <TOut2>().Module)
            {
                if (Keep.IsLeft(combine))
                {
                    return(this as Source <TOut2, TMat3>);
                }

                if (Keep.IsRight(combine))
                {
                    return(MapMaterializedValue(_ => NotUsed.Instance) as Source <TOut2, TMat3>);
                }

                return(MapMaterializedValue(value => combine(value, (TMat2)(object)NotUsed.Instance)) as Source <TOut2, TMat3>);
            }

            var flowCopy = flow.Module.CarbonCopy();

            return(new Source <TOut2, TMat3>(Module
                                             .Fuse(flowCopy, Shape.Outlet, flowCopy.Shape.Inlets.First(), combine)
                                             .ReplaceShape(new SourceShape <TOut2>((Outlet <TOut2>)flowCopy.Shape.Outlets.First()))));
        }