Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created October 26, 2017 14:24
Show Gist options
  • Save dcomartin/d582626074ffab34912f4a892096eba3 to your computer and use it in GitHub Desktop.
Save dcomartin/d582626074ffab34912f4a892096eba3 to your computer and use it in GitHub Desktop.
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"
@joshi1983
Copy link

I made a little spelling correction at https://gist.github.com/joshi1983/0c683b5d933bd1c59714f3b8581df3e1.

Maybe you'd want to merge for fix it yourself?

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