Last active
December 10, 2015 01:19
-
-
Save ToJans/4357959 to your computer and use it in GitHub Desktop.
Currying in C#... yes or no ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ahum... Pattern matching - not currying