Usage and meaning of Tap extension method
See original GitHub issueWe’re using CSharpFunctionalExtensions package in our projects more than a year and we appreciated the changes of many OnSuccess methods to separate methods with different meaning, such as Tap, Bind etc.
After some using our team got an intuitive understanding of when to use each of them and we wrote not totally functional, but easy-readable and clear constructions such as:
await GetAvailability(request, languageCode)
.Bind(ConvertCurrencies)
.Map(ApplyMarkups)
.Map(Convert)
.Tap(SaveResult)
When I read these lines I know that GetAvailability returns a Result<T1>, then passes it to the ConvertCurrencies, which returns result of another type (Result<T2>) and so on. When I see a usage of Tap it looks like a method that doing nothing with returning result, just doing some job with no result (or having result as a Task). And as I understand, Tap has the same meaning in other languages.
But during one of the code reviews we’ve found out that there are some Tap overloads that do change the returning result and this was totally surprising:
/// <summary>
/// If the calling result is a success, the given function is executed and its Result is checked. If this Result is a failure, it is returned. Otherwise, the calling result is returned.
/// </summary>
public static async Task<Result<T, E>> Tap<T, K, E>(this Task<Result<T, E>> resultTask, Func<T, Result<K, E>> func)
{
Result<T, E> result = await resultTask.DefaultAwait();
return result.Tap(func);
}
Could you tell why it was done in such way and what is the new meaning of the Tap in terms of the library?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:30 (14 by maintainers)

Top Related StackOverflow Question
@mingazhev ah I see your point, Name is confusing indeed 😃
Several days ago I was discussing
Taps andTapIfs with one of my colleagues and he admitted that he does not understand code withTaps exactly because of the different semantics.@mingazhev I think you should create a fork first, commit/push your changes and open a PR then. This guide covers all the steps : https://github.com/MarcDiethelm/contributing/blob/master/README.md