Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# Partial application and Currying
#region Partial application and Currying
static class FuncHelper
{
public static Func<T2, T3, T4, TResult> ApplyPartial<T1, T2, T3, T4, TResult>
(Func<T1, T2, T3, T4, TResult> function, T1 arg1)
{
return (b, c, d) => function(arg1, b, c, d);
}
public static Func<T2, T3, TResult> ApplyPartial<T1, T2, T3, TResult>
(Func<T1, T2, T3, TResult> function, T1 arg1)
{
return (b, c) => function(arg1, b, c);
}
public static Func<T2, TResult> ApplyPartial<T1, T2, TResult>
(Func<T1, T2, TResult> function, T1 arg1)
{
return arg2 => function(arg1, arg2);
}
public static Func<TResult> ApplyPartial<T1, TResult>
(Func<T1, TResult> function, T1 arg1)
{
return () => function(arg1);
}
public static Func<T1, Func<T2, Func<T3, TResult>>> Curry<T1, T2, T3, TResult>
(Func<T1, T2, T3, TResult> function)
{
return a => b => c => function(a, b, c);
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.