Created
March 10, 2019 17:43
-
-
Save amir734jj/054d7c026c52e56c8343b010d8558c4e to your computer and use it in GitHub Desktop.
csharp functional extensions
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
public static Func<TArg1, Func<TArg2, TResult>> Curry<TArg1, TArg2, TResult>(this Func<TArg1, TArg2, TResult> source) | |
{ | |
return x => y => source(x, y); | |
} | |
public static Func<TArg1, Func<TArg2, Func<TArg3, TResult>>> Curry<TArg1, TArg2, TArg3, TResult>(this Func<TArg1, TArg2, TArg3, TResult> source) | |
{ | |
return x => y => z => source(x, y, z); | |
} | |
public static Func<TArg1, TArg2, TResult> UnCurry<TArg1, TArg2, TResult>(this Func<TArg1, Func<TArg2, TResult>> source) | |
{ | |
return (x, y) => source(x)(y); | |
} | |
public static Func<TArg1, TArg2, TArg3, TResult> UnCurry<TArg1, TArg2, TArg3, TResult>(this Func<TArg1, Func<TArg2, Func<TArg3, TResult>>> source) | |
{ | |
return (x, y, z) => source(x)(y)(z); | |
} | |
public static Func<TArg1, TResult2> Compose<TArg1, TResult1, TResult2>(this Func<TArg1, TResult1> source, Func<TResult1, TResult2> func) | |
{ | |
return x => func(source(x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment