Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication12
- {
- class Program
- {
- static void Main(string[] args)
- {
- Func<int, int, int> add = (x, y) => x + y;
- Console.WriteLine(add(1, 1)); // 2
- var curriedAdd = add.Curry();
- var add1 = curriedAdd(1);
- Console.WriteLine(add1(2)); // 3
- Console.ReadLine();
- }
- }
- public static class Extensions
- {
- public static Func<TArg, Func<TArg2, TResult>> Curry<TArg, TArg2, TResult>(this Func<TArg, TArg2, TResult> source)
- {
- return arg1 => { return arg2 => { return source(arg1, arg2); }; };
- }
- }
- }
Add Comment
Please, Sign In to add comment