Created
October 26, 2017 14:24
-
-
Save dcomartin/d582626074ffab34912f4a892096eba3 to your computer and use it in GitHub Desktop.
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
public Maybe<int> Decrement(int number) | |
{ | |
if (number <= 0) | |
{ | |
reutrn Maybe<int>.None; | |
} | |
return Maybe<int>(number-1); | |
} | |
Maybe<int> test1 = Decrement(100); | |
test1.Match( | |
some: x => Console.Writeline($"It has a value: {x}"), | |
none: () => Console.Wreiteline("It has no value") | |
); | |
// output from test1 would be: "It has a value: 99" | |
Maybe<int> test2 = Decrement(0); | |
test1.Match( | |
some: x => Console.Writeline($"It has a value: {x}"), | |
none: () => Console.Wreiteline("It has no value") | |
); | |
// output from test2 would be: "It has no value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made a little spelling correction at https://gist.github.com/joshi1983/0c683b5d933bd1c59714f3b8581df3e1.
Maybe you'd want to merge for fix it yourself?