vkhorikov/CSharpFunctionalExtensions

Feature: Maybe.Execute() when there is no value

seangwright opened this issue · 3 comments

Maybe.Execute() is effectively shorthand for:

Maybe<int> maybe = 10;

maybe.Match(
    number => Console.WriteLine(number),
    () => {});

I occasionally come across situations where I want the reverse:

Maybe<int> maybe = Maybe<int>.None;

maybe.Match(
    _ => {},
    () => Console.WriteLine("There's nothing here"));

Can we add an overload to Maybe.Execute that takes an Action instead of an Action<T> and would be called when there is no value?

Maybe<int> maybe = Maybe<int>.None;

maybe.Execute(() => Console.WriteLine("There's nothing here"));

I'm afraid such operator would cause confusion. Maybe Compensate would be a better one?

I agree regarding confusion, but not sure about Compensate. What about ExecuteNoValue ?

Sounds good!