Guest User

Untitled

a guest
Dec 10th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication12
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Func<int, int, int> add = (x, y) => x + y;
  13.             Console.WriteLine(add(1, 1)); // 2
  14.             var curriedAdd = add.Curry();
  15.             var add1 = curriedAdd(1);
  16.             Console.WriteLine(add1(2)); // 3
  17.             Console.ReadLine();
  18.         }
  19.     }
  20.  
  21.     public static class Extensions
  22.     {
  23.         public static Func<TArg, Func<TArg2, TResult>> Curry<TArg, TArg2, TResult>(this Func<TArg, TArg2, TResult> source)
  24.         {
  25.             return arg1 => { return arg2 => { return source(arg1, arg2); }; };
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment