Tap seems limited since you cannot halt execution on failure
See original GitHub issueTap is very useful in that you can use it to return the passed in result and do multiple operations on a single result object. For example.
return getMyResult()
.Tap(x => DoWork1(x))
.Tap(x => DoWork2(x))
.Tap(x => DoWork3(x));
However, sometimes you would like to return the result and still depend on whether the DoWork() method failed. If you could assume that Funcs passed to DoWork all returned the same result type as the “parent” result, that would be useful.
I find myself writing extensions methods like the following:
public static async Task<Result<T>> Tap<T>(this Task<Result<T>> resultTask, Func<T, Task<Result<T>>> func)
{
var result = await resultTask.ConfigureAwait(Result.DefaultConfigureAwait);
if (!result.IsSuccess) return result;
var tapResult = await func(result.Value).ConfigureAwait(Result.DefaultConfigureAwait);
return tapResult.IsFailure
? tapResult
: result;
}
In this case, the flow would be identical, except that execution would stop when a tap Func returns a failed result.
What is the reasoning behind having the result of a Tap operation be ignored in the railway flow?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
How to fix a dodgy tap that won't turn on properly - YouTube
Hamish the Plumber demonstrates how to fix a dodgy basin tap that won't turn on properly. Watch in real time as he services...
Read more >Scan Troubleshooting
These limits are not always obvious since they may not cause error messages in your PHP error logs, and may make the scan...
Read more >Solved: Runner.Halt generates "Execution is already compl...
It's as if the .Halt procedure is trying to do something after the script has ended. The other 4 statements in the 'If"...
Read more >'Insufficient storage': How to fix that error in Android and iOS
When iOS won't install an OS update for lack of space · Open the Settings app. · Tap General, then tap Usage. ·...
Read more >COLLECTING YOUR JUDGMENT - California Courts
CHAPTER 10: TAKING ACTION AGAINST AN UNPAID JUDGMENT. Lien on Real Property (Starting the Process on Lien). (Lien on Debtor's business assets).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Addressed as part of PR #192
I do it this way:
UpdateCustomer()returns a Result<T> containing a value that we aren’t interested in.DoWork()returns a Result with no value.