Created
July 16, 2015 16:23
-
-
Save gsscoder/609a95695fb5ec0875dc to your computer and use it in GitHub Desktop.
C# Partial application and Currying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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