Skip to content

Instantly share code, notes, and snippets.

@amir734jj
Created March 10, 2019 17:43
Show Gist options
  • Save amir734jj/054d7c026c52e56c8343b010d8558c4e to your computer and use it in GitHub Desktop.
Save amir734jj/054d7c026c52e56c8343b010d8558c4e to your computer and use it in GitHub Desktop.
csharp functional extensions
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