I am looking for a way to chain several delegates so the result from one becomes the input of the next. I am trying to use this in equation solving program where portions ar
This might help:
public static Func Compose(Func innerFunc, Func outerFunc) {
return arg => outerFunc(innerFunc(arg));
}
This performs function composition, running innerFunc and passing the result to outerFunc when the initial argument is supplied:
Func floor = Math.Floor;
Func convertToInt = Convert.ToInt32;
Func floorAndConvertToInt = Compose(floor, convertToInt);
int result = floorAndConvertToInt(5.62);
Func floorThenConvertThenAddTen = Compose(floorAndConvertToInt, i => i + 10);
int result2 = floorThenConvertThenAddTen(64.142);