I\'m creating a Validator class. I\'m attempting to implement the Linq SelectMany extension methods for my validator to be able to compose
The equivalent of Haskell's function composition operator
(.) :: (b->c) -> (a->b) -> (a->c)
f . g = \ x -> f (g x)
would in C# probably be something like
static Expression> Compose(
Expression> f,
Expression> g)
{
var x = Expression.Parameter(typeof(A));
return Expression.Lambda>(
Expression.Invoke(f, Expression.Invoke(g, x)), x);
}
Is this what you're looking for?
Example:
Compose(y => y.ToString(), x => x + 1).Compile()(10); // "11"