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.