Saw a post about hidden features in C# but not a lot of people have written linq/lambdas example so... I wonder...
What\'s the coolest (as in the most
Some basic functionals:
public static class Functionals
{
// One-argument Y-Combinator.
public static Func Y(Func, Func> F)
{
return t => F(Y(F))(t);
}
// Two-argument Y-Combinator.
public static Func Y(Func, Func> F)
{
return (t1, t2) => F(Y(F))(t1, t2);
}
// Three-arugument Y-Combinator.
public static Func Y(Func, Func> F)
{
return (t1, t2, t3) => F(Y(F))(t1, t2, t3);
}
// Four-arugument Y-Combinator.
public static Func Y(Func, Func> F)
{
return (t1, t2, t3, t4) => F(Y(F))(t1, t2, t3, t4);
}
// Curry first argument
public static Func> Curry(Func F)
{
return t1 => t2 => F(t1, t2);
}
// Curry second argument.
public static Func> Curry2nd(Func F)
{
return t2 => t1 => F(t1, t2);
}
// Uncurry first argument.
public static Func Uncurry(Func> F)
{
return (t1, t2) => F(t1)(t2);
}
// Uncurry second argument.
public static Func Uncurry2nd(Func> F)
{
return (t1, t2) => F(t2)(t1);
}
}
Don't do much good if you don't know how to use them. In order to know that, you need to know what they're for: