CSharpFunctionalExtensions
CSharpFunctionalExtensions copied to clipboard
Add Tap* extensions to Maybe
I find the existing Execute/ExecuteNoValue extensions a bit inconvenient, due to:
- Naming that could just reuse the established
Tapnomenclature (used inResultalready) voidreturn type prohibiting fluent method chaining.
With Execute the flow looks as follows:
var maybe = GetMaybe();
maybe.ExecuteNoValue(() => logger.LogWarning("There was no value"));
return maybe.Or(someDefaultValue);
With the new Tap, it could be:
return GetMaybe()
.TapNoValue(() => logger.LogWarning("There was no value"))
.Or(someDefaultValue);
I also added Obsolete attribute to Execute since I think it's not really needed when Tap is there. Please do let me know if that's alright.
The new code is really just a copy of existing Execute/ExecuteNoValue code with added return functionality. Tests are also mostly copied.