Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Created July 16, 2015 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gsscoder/609a95695fb5ec0875dc to your computer and use it in GitHub Desktop.
Save gsscoder/609a95695fb5ec0875dc to your computer and use it in GitHub Desktop.
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