When to use Match or Tap? #526
Unanswered
lloydjatkinson
asked this question in
Q&A
Replies: 1 comment
-
The idea here is that The provided logging example perfectly matches with the side effect use case. And CSharpFunctionExtensions forces you to use extensions, so I'll rewrite your code to foreach (var feed in feeds)
{
await this.syndicationFeedHttpClient
.GetSyndicationFeedAsync(feed.Uri);
.Tap(success => successfulFeeds.Add(feed))
.TapError(failed => failedFeeds.Add(feed))
.Tap(success => this.logger.LogInformation("Parsed feed {feedUri} [{feedItemsCount} items]", feed.Uri, successFeed.Items.Count()))
.TapError(failed => this.logger.LogError("Failed to parse feed {feedUri}", feed.Uri));
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm unsure where to use Tap vs Match when using Result. These two blocks are equivalent in this use case. When should one be used over the other? I'm performing side effects in two areas (logging), does that impact the decision?
Beta Was this translation helpful? Give feedback.
All reactions