EDN Admin
Well-known member
Hi,
With first-class functions, every n-ary function can be transformed into a composition of n unary functions, that is, into a curried function:
public static Func<T1, Func<T2, TRes>> Curry<T1, T2, TRes>(this Func<T1, T2, TRes> f)
{
return (x => (y => f(x, y)));
}
Func<int, int, int> lam1 = (x, y) => x + y;
Func<int, Func<int, int>> lam2 = x => (y => x + y);
Func<int, int> lam3 = lam2(3); // partial application
// Curryfying
Func<int, int> lam4 = lam1.Curry()(3); // partial applicationBest Regards,
View the full article
With first-class functions, every n-ary function can be transformed into a composition of n unary functions, that is, into a curried function:
public static Func<T1, Func<T2, TRes>> Curry<T1, T2, TRes>(this Func<T1, T2, TRes> f)
{
return (x => (y => f(x, y)));
}
Func<int, int, int> lam1 = (x, y) => x + y;
Func<int, Func<int, int>> lam2 = x => (y => x + y);
Func<int, int> lam3 = lam2(3); // partial application
// Curryfying
Func<int, int> lam4 = lam1.Curry()(3); // partial applicationBest Regards,
View the full article