Skip to content

Instantly share code, notes, and snippets.

@ToJans
Last active December 10, 2015 01:19
Show Gist options
  • Save ToJans/4357959 to your computer and use it in GitHub Desktop.
Save ToJans/4357959 to your computer and use it in GitHub Desktop.
Currying in C#... yes or no ?
dynamic fizzbuzz = new Curry()
.On<int>()
.When(x => x % 15 == 0).Do(x => "fizzbuzz")
.When(x => x % 3 == 0).Do(x => "fizz")
.When(x => x % 5 == 0).Do(x => "buzz")
.Do(x=>x)
.On<IEnumerable<int>>()
.Do((s, r) => from val in r select s(r))
.On<string>()
.When("fizzbuzz").Do(x => "Aha, you found the easter egg!")
.On<int, int>()
.When((from, to) => to >= from).Do((s, from, to) => s(IEnumerable<int>.Range(from, to - from)));
fizzbuzz(1,100);
fizzbuzz("muahahaha"); // throws exception
fizzbuzz("fizzbuzz"); // returns "Aha, you found the easter egg!"
@ToJans
Copy link
Author

ToJans commented Dec 22, 2012

Ahum... Pattern matching - not currying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment