Does c#'s type system have the ability to specify a function that takes an enumerable number of functions which commute to form a pipeline?
The effect would be similar to chaining, but instead of
var pipeline = a.Chain(b).Chain(c)
one could write
var pipeline = CreatePipeline(a,b,c)
where a, b and c are functions? I have included a bit of sample code to illustrate, thanks.
void Main()
{
Func<int, string> a = i => i.ToString();
Func<string, DateTime> b = s => new DateTime(2000,1,1).AddDays(s.Length);
Func<DateTime, bool> c = d => d.DayOfWeek == DayOfWeek.Wednesday;
//var myPipeline = CreatePipeline(a, b, c);
Func<int, bool> similarTo = i => c(b(a(i))) ;
Func<int, bool> isThisTheBestWeCanDo = a.Chain(b).Chain(c);
}
public static class Ext{
//public static Func<X, Z> CreatePipeline<X,Z>(params MagicFunc<X..Y>[] fns) {
// return
//}
public static Func<X, Z> Chain<X,Y,Z>(this Func<X,Y> a, Func<Y,Z> b)
{
return x => b(a(x));
}
}