Skip to content

Add Tap* extensions to Maybe#602

Merged
vkhorikov merged 5 commits intovkhorikov:masterfrom
marcinjahn:add-maybe-tap
Mar 2, 2026
Merged

Add Tap* extensions to Maybe#602
vkhorikov merged 5 commits intovkhorikov:masterfrom
marcinjahn:add-maybe-tap

Conversation

@marcinjahn
Copy link
Copy Markdown
Contributor

I find the existing Execute/ExecuteNoValue extensions a bit inconvenient, due to:

  1. Naming that could just reuse the established Tap nomenclature (used in Result already)
  2. void return 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.

@vkhorikov
Copy link
Copy Markdown
Owner

This looks good. Could you re-push the PR? looks like there was an issue during build

Maybe.Tap and Maybe.TapNoValue are able to take over the deprecated
methods with added functionality.
@marcinjahn
Copy link
Copy Markdown
Contributor Author

@vkhorikov Is everything alright now? 🙂

- Fix TapNoValue.ValueTask.cs return type from Task<Maybe<T>> to ValueTask<Maybe<T>>
- Fix Obsolete messages on Execute methods: "Use TapValue instead" -> "Use Tap instead"
- Fix typo in test method names: "Lef" -> "Left"
- Add missing TapNoValue tests for HasValue (no-op) scenario
- Add DependentUpon entries in both csproj files for all new Tap/TapNoValue files
- Fix csproj conditional compilation: use TargetFramework instead of DefineConstants

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vkhorikov vkhorikov merged commit 4bca207 into vkhorikov:master Mar 2, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants