Skip to content

Instantly share code, notes, and snippets.

@s-amemiya
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save s-amemiya/0054c67102f7780e07f7 to your computer and use it in GitHub Desktop.

Select an option

Save s-amemiya/0054c67102f7780e07f7 to your computer and use it in GitHub Desktop.
using System;
class Program
{
static void Main()
{
Func<int, Func<int, int>> curriedSum = lhs => rhs => lhs + rhs; // currying
Console.WriteLine(curriedSum(1)(2)); // 3
Console.WriteLine(curriedSum(4)(5)); // 9
var onePlus = curriedSum(1);
Console.WriteLine(onePlus(1)); // 2
Console.WriteLine(onePlus(211)); // 212
var twoPlus = curriedSum(2);
Console.WriteLine(twoPlus(1)); // 3
Console.WriteLine(twoPlus(211)); // 213
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment