Skip to content

Instantly share code, notes, and snippets.

@joshi1983
Forked from dcomartin/maybe.cs
Last active October 26, 2017 14:33
Show Gist options
  • Save joshi1983/0c683b5d933bd1c59714f3b8581df3e1 to your computer and use it in GitHub Desktop.
Save joshi1983/0c683b5d933bd1c59714f3b8581df3e1 to your computer and use it in GitHub Desktop.
Fixed misspelled return keyword in Decrement method
public Maybe<int> Decrement(int number)
{
if (number <= 0)
{
return 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