How to implement a true function pipeline in C #?

How to create a true function pipeline using C #? I got some idea as described below, but this is not a real pipeline

public static IEnumerable<T> ForEachPipeline<T>(this IEnumerable<T> source, params Func<T, T>[] pipeline)
{
 foreach (var element in source) {
  yield return ExecutePipeline(element, pipeline);
 }
}

private static T ExecutePipeline<T>(T element, IEnumerable<Func<T, T>> jobs)
{
 var arg = element;
 T result = default(T);
 foreach (var job in jobs) {
  result = job.Invoke(arg);
  arg = result;
 }
 return result;
}

In the above code, each element IEnumerable<T>could get into the pipeline only after the previous element completed execution of all functions (i.e., exits the pipeline), but according to the definition, if it element1completes execution func1and start execution func2, it element2should start execution by then func1etc., thereby supporting the continued flow of data in the pipeline.

Is it possible to implement such a scenario in C #? If possible, please give me an example code.

+5
3

: , ( - ). FIFO, "". ( , concurrency) , , . .NET4 "Parallel".

"" , N "" Parallel.ForEach - , , .

: . ().

0

, . , , , .

, , , , , , , .

0

, , , . GoF, , GoF:

http://www.dofactory.com/Patterns/PatternChain.aspx#_self1

, "" - , , ( "where" ).

Also, take a look at the PLINQ structure. I know that this is not quite what you are looking for (there, IS's intention to do several tasks in parallel), but it can give you some good ideas.

0
source

All Articles